Thursday, December 9, 2010

Contract Upload Using BAPI_CONTRACT_CREATE

Using BAPI_CONTRACT_CREATE is quite tricky when you want to add customised fields, conditions and header/item texts.

Just sharing my experience for my own future references and to anyone who'll benefit from this as I can't find any specific help on the net on this.


CUSTOMISED FIELDS - LINE ITEMS LEVEL

In my case, it's ZZREGION and ZZTECH fields that were appended to table EKKN.
In ME31K, these fields are located on item level, on 'Account Assignment' tab - 'More' tab - then you'll get region/technology fields.

In BAPI, you have to use structure  BAPI_TE_MEOUTACCOUNT as in the code excerpts below:

*-----------------------------------Customised Field ZZREGION & ZTECH - Item---------------------------------------*

    lt_extensionin-structure = 'BAPI_TE_MEOUTACCOUNT'.
    lt_regiontech-item_no = '00010'.
    lt_regiontech-serial_no = '01'.
    lt_regiontech-zzregion  = 'EAST'.
    lt_regiontech-zztech    = 'C'.
    CONCATENATE lt_regiontech-item_no lt_regiontech-serial_no lt_regiontech-zzregion lt_regiontech-zztech INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.

CUSTOMISED FIELDS - HEADER LEVEL

Working With CHECKBOXES:
- If it's standard checkbox field, we can move directly to BAPI contract header data.
- If it's CUSTOMIZED checkbox field, we have to find the structure and use EXTENSIONIN to append data.

Example 1:
Checkbox: 'Notification not required'.
(Field EKKO-WEAKT in ME33K -  Header - Details) - Standard field

In BAPI, use structure BAPI_TE_MEOUTHEADER to move the data as in below:


*-----------------------------------Customised Field ZZSDRO - Header --------------------------------------*

    lt_extensionin-structure = 'BAPI_TE_MEOUTHEADER'.
    PERFORM fill_leading_zero USING lw_ufile-ebeln CHANGING lt_zzsdro-number.
    lt_zzsdro-zzcode    = lc_zzcode.
    lt_zzsdro-zzamount  = lc_zzamount.
    lt_zzsdro-zzsdro    = lw_ufile-zsdro.
    CONCATENATE lt_zzsdro-number lt_zzsdro-zzcode lc_zzamount lt_zzsdro-zzsdro INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.


    lt_extensionin-structure = 'BAPI_TE_MEOUTHEADERX'.
    PERFORM fill_x_structure CHANGING lt_zzsdrox.
    PERFORM fill_leading_zero USING lw_ufile-ebeln CHANGING lt_zzsdrox-number.
    CONCATENATE lt_zzsdrox-number lt_zzsdrox-zzcode lt_zzsdrox-zzamount lt_zzsdrox-zzsdro INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.

**Remember to concatenate ALL fields BEFORE the fields u need (zzcode & zzamount) in the BAPI structure before moving it to structure field EXTENSIONIN-VALUEPART1.
**Or try to point to the field directly: lt_extensionin-valuepart1+4(2) = lt_zzsdrox-zzcode.



Example 2:

Checkbox: 'Allow Stock To DRO'.
(Field ZZSDRO in ME33K -  Header - Details) - Custom field

- Use BADI


CONDITIONS
- To Be Continued....
... And so the screenshots! Will upload later.


***UPLOAD TO UNIX***
Upload tcode: CG3Z
Check uploaded file in unix: AL11








With Much Love,
The Rookie ABAPer

Wednesday, June 16, 2010

To Compare Programs In Different Clients

These are the steps to identify if there's any difference between two programs with the same name in different clients (e.g. ECD & ECP):

1. Go to SE38 and key in the program name.
2. Click Utilities - Versions - Version Management
3. Click REMOTE comparison button.
4. Key in target system (e.g. ECP). Click the tick button.
5. Click the REMOTE comparion button.
6. The screen will show the difference if there's any.


With Much Love,
The Rookie ABAPer

Wednesday, March 31, 2010

Condition Values For PO & Contract

I just have to jot this down! Took me forever to get the KNUMH value for contract!
Trickkayyy! :P

PO: 

To get the Item Conditions Value as in ME23N (Conditions tab at item level):

SELECT SINGLE kbetr FROM konv
      INTO gv_kbetr
      WHERE knumv = lv_knumv AND      "lv_knumv = EKKO-knumv
                      kschl = 'ZAVS'.

Item Conditions Value = GV_KBETR

To get the Item Conditions Type Text:

SELECT SINGLE vtext FROM t685t    
      INTO gv_vtext
      WHERE spras = 'E'        AND
                      kvewe = 'A'     AND
                      kappl = 'M'      AND
                      kschl = 'ZAVS'.     "based on your condition type

Item Conditions Text = GV_VTEXT.

Contract:

To get the Item Conditions Value as in ME33K:

 "lv_ebeln & lv_ebelp is from EKPO
CONCATENATE lv_ebeln lv_ebelp INTO lv_vakey.
SELECT SINGLE knumh FROM konh
      INTO lv_knumh
      WHERE vakey = lv_vakey.


IF lv_knumh IS NOT INITIAL.
   SELECT SINGLE kbetr FROM konp
      INTO gv_kbetr
      WHERE knumv = lv_knumv AND  "lv_knumv = EKKO-knumv
                      kschl = 'ZA00'.
ENDIF.


Item Conditions Value = GV_KBETR

To get the Item Conditions Type TEXT:

 SELECT SINGLE vtext FROM t685t    
      INTO gv_vtext
      WHERE spras = 'E'        AND
                      kvewe = 'A'     AND
                      kappl = 'M'      AND
                      kschl = 'ZA00'.     "based on your condition type

Item Conditions Text = GV_VTEXT.



With Much Love,

The Rookie ABAPer

Friday, March 26, 2010

Creating Custom Page Format For Smartforms/Sapscripts

****Copied from http://sample-code-abap.blogspot.com/2009/05/creating-custom-page-format-for.html**** This is so helpful for me!

You can print any size of output from SAP, it all depends on what page format is defined and configured in your SAP system. Most of the standard page format are already defined in SAP but often you come across the situation where the required output doesn’t even come close to any of these predefined page format. Printing cheques and receipts are some common example. Defining and configuring Page format is multi-step process and often is printer specific. In short its very easy to get your setting wrong and situation is worse when printer is physically away from you.

Its very important to understand how this page format works in SAP. The process starts with defining the Page Format, but you need few more setting to actually print this page size on printer. Page format just define the size of page for sapscript (this size info defined in page format is not passed to printer), next step is to define Format type which defines 'Type of format' and what orientation are allowed with this page format. It is important to note that Page Format and Format type should have same name. Well, you can argue why do we need to define Format Type. To find out that, which you may find bit confusing refer sap note 2374. Still you can not print with this page size on printer. To allow printer to use this new page format you need to add this page format to device type of printer. This step will enable you to print the output but correct page size information will not be passed to printer. You need to actually put printer specific code to set desire page size on printer.

Before we start it worth checking where do we specify page format in sapscript.



Now let us go through each step with screen shot. You need to have access to transaction SPAD and changes to the repository and cross-client customizing should be permitted in the client where you will create/change page format.

Execute transaction SPAD. By default transaction will not show all the tabs, you need to click on 'Full administration' to get the desire tab.



Go to 'Device Types' tabs and hit 'Display' button next to Page Formats.



On next screen hit 'change' button then you will button to create new Page format, now press New button.



Fill in the required input, below is an example.



Congrats you just created a new page format.

At this stage you can use this page format in sapscript, however you can not print that sapscript. This information of page dimension is just for sapscript. You will get warning message while adding page format to sapscript 'There is no form for page format XYZ' and error message while printing 'Device type ABC does not support page format XYZ'.

Next step is to create Format Type. Remember Format Type should have same name as your Page Format name. Start from transaction SPAD, on 'Device Type’ tab press display button next to 'Format Type'. Click on change then new button and create Format Type as shown in screen-shot below.







To allow printer to use this new Format Type you need to add this format to device type of printer. You can find the device type of printer from table TSP03D, it is stored in field PATYPE.

On 'Device Types' table enter Device name and press Display button next to it.



Go in change mode and press 'Formats'



On next screen press ‘New’ button and enter 'Format Type'.



Once the format type added to device type, double click on the line (on first column). On next screen as shown below double click on 'Printer initialization'



Input following code, this code will actually set the page length on printer. Page length is defined under the code '# set page length 72 lines'. Its defined in hex and is defined in lines. You might have to do some math to convert your page length from CM/MM to line considering lines per inch value set.

For example in this particular case the page length define Page format is 102 mm which is 4 inches. Using setting 6 lines per inch 4 inches comes out to be 24 lines. (ok, the comment is wrong, it should be '# set page length 24 lines'). And in hex 24 is represented as 18.





You might need to add this format and put this code for each device type of each printer on which you are planning to print the output.

With all these setting in place you can, hopefully, print the output on printer with correct page format.



With Much Love,

The Rookie ABAPer

Wednesday, February 24, 2010

As Simple As SY-ABCDE!

1. In a character string where you want to check whether a string contains any alphabets, try using this one!

    e.g. TRANSLATE lv_var TO UPPERCASE.
           IF lv_test CA sy-abcde.                            "Contains Any A to Z
           .........

SY-ABCDE only checks for CAPITALS A-Z, hence the need to translate the variable to uppercase first.

2. To check whether a char datatype variable contains only numeric characters or not, use this:

    e.g. IF lv_var CN '1234567890.'               "Doesn't contain 0 to 9 and decimal point (.)           .........

You might as well use sy-abcde to check if user has keyed in other than numerics characters, but it is safer to use the latter (1234567890.) because there is possibility that user might key in symbols as well.

NOTES: Logical Expressions for String Fields

CO - Contains
CN - Does Not Contain / Inverse of Contains
CA - Contains Any
NA - Contains None / Inverse of Contains Any
CS - Contains String
NS - Does Not Contain String / Inverse of Contains String
CP - Contains Pattern
NP - Does Not Contain Pattern / Inverse of Contains Pattern




With Much Love,

The Rookie ABAPer

Dealing With Multiple Copies

Scenario: There are times when the client wanted to print 4 copies for each of their Delivery Order (DO) form (all with the same DO number). They want different texts to be printed on each of the 4 copies.

Solution:

1. Create a new window with the Window Type - 'Copies Window'.

2. Select 'Only Copies - Copies Differ'.

3. Insert program lines or texts under the node, as in my case:

    - page 1 should print 'Delivery Copy'
    - page 2 should print 'Warehouse Copy'
    - page 3 should print 'Vendor Copy'
    - page 4 should print 'Area Manager Copy'

4. The current 'Copy Number' can be obtained using &SFSY-COPYCOUNT&.

5. Or if you don't want to refer to it directly so you can manipulate it in you program line, just declare a global variable and move the value to your own variable, e.g:

    @Global Definitions:
        gv_copycount LIKE sfsy-copycount.

    @Program Lines:
       MOVE sfsy-copycount TO gv_copycount. 
       IF gv_copycount = '001'.
         gv_copytext = 'Delivery Copy'.
       ENDIF.


With Much Love,
The Rookie ABAPer

HELLO WORLD!

I created this blog simply as a platform for sharing my own ABAP & SAP notes with you, you and you!

We all know that GOOGLE is the tool! Most of the time, especially when you're already familiar with the SAP environment, most ABAP stuff can be found on the net! I wouldn't say if you're really new in this field, Google will be much of a help, because it won't. You have to learn it from the Gurus :)

The trick is just to google it up with the BEST KEYWORD you could think of, then wallah! It's all there!

And if I've learnt anything in the past on ABAP, it would be about not reinventing the wheel. Most of the obstacles you had in ABAP was already faced by others, so it's the matter of finding the right keyword, hence the right solution. It's very unlikely that you're facing some truly unique problems! :)

So, I'll just write anything I figure would be useful here, as it is very likely that these things will be revisited next time around! The time when I may have forgotten the solutions, or the time when I've ran out of keywords to google.

Sooooooo, happy learning, and stay optimist (and cute!) haha.


With Much Love,
The Rookie ABAPer