Quantcast
Channel: SCN : All Content - ABAP Platform Developer Center
Viewing all 29 articles
Browse latest View live

USE CUSTOM CONTAINER FOR MULTIPLE LINE DISPLAY AND SAVE

$
0
0

Hiii,

 

This document used to get know how to use custom container to make an multiple lines editable text box...

 

INTRODUCTION: Use a custom container to get multiple text data from file, or by writing and to save data in cluster database.

Steps:

  1. Make a custom container in sceen.
  2. Make object of cl_gui_cutom container.
  3. Make object of cl_gui_textedit.
  4. Use method of class cl_gui_textedit to link subsceen container to main sceen subsceen area and to use it.
  5. Use set_text_as_r3table to set data in custom_container and use get_text_as_r3table to get data from custom_container to internal table.

Advantage:

  1. Use of objects.
  2. Use of cluster database to save data. So to increase speed and save database space also using INDX database of cluster database.
  3. Can able to get data from any document into our custom container.
  4. Can able to make document using text in custom container.
  5. Save multiple line data in the database.

Step-by-step

  1. First make a tab in which use a sub screen subl_doc for calling of sceen contains of custom container.

 

 

 

 

2. Second step make a sceen on which use a custom container name as TEXTEDITOR1.

 

  

 

 

3. Define the object refrences in top part of calling screen using below coding:

 

   

CONSTANTS texte TYPE n LENGTH 5VALUE256.

DATA: editor TYPEREFTO cl_gui_textedit,
container
TYPEREFTO cl_gui_custom_container.

DATA  g_repid TYPE sy-repid.
DATA  g_dynnr TYPE sy-dynnr.
DATA  g_mytable(256) TYPEcOCCURS0.
DATA  t_text TYPESTANDARDTABLEOF tline.
DATA  j_text TYPESTANDARDTABLEOF tline.
DATA  w_text TYPE tline.
DATA  w_mytable(texte) TYPEc .
CLASS cl_gui_cfw DEFINITIONLOAD. "to load class
DATA  v_docno(22).
DATA i_docno TYPE n LENGTH 22.
DATA: text1(132),
len
TYPEi,
len1
TYPEi,
text2(
132).

  1. Now call this sub screen using the below coding in main sceen:


PROCESS BEFORE
OUTPUT.
module clear_syucomm.

CALL SUBSCREEN subl_mat INCLUDING 'YEXPORT_PROCES''0104'.
CALL SUBSCREEN subl_bak INCLUDING 'YEXPORT_PROCES''0105'.
CALL SUBSCREEN subl_doc INCLUDING 'YEXPORT_PROCES''0106'.“sub screen calling for                                                             “ custom container

*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TCNTRL'
*  MODULE TCNTRL_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TCNTRL_CHANGE_COL_ATTR.
*  LOOP AT   IT_YLCP
*       WITH CONTROL TCNTRL
*       CURSOR TCNTRL-CURRENT_LINE.
***    MODULE TCNTRL_GET_LINES.
**&SPWIZARD:   MODULE TCNTRL_CHANGE_FIELD_ATTR
*  ENDLOOP.

MODULE status_0102.
*
MODULE PBO_102.      “Use to make objects for custom container

PROCESS AFTER
INPUT.

MODULE exit_prog_102 ATEXIT-COMMAND.


call SUBSCREEN subl_mat.
call SUBSCREEN subl_bak.
call SUBSCREEN subl_doc.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TCNTRL'
*  LOOP AT IT_YLCP.
*    CHAIN.
*      FIELD IT_YLCP-SRLNO.
*      FIELD IT_YLCP-MATNR.
*      FIELD IT_YLCP-MAKTX.
*      FIELD IT_YLCP-LCMAKTX.
*      FIELD IT_YLCP-VRKME.
*      FIELD IT_YLCP-FKIMG.
*      FIELD IT_YLCP-kurrf.
*      FIELD IT_YLCP-DMBTR.
*      MODULE TCNTRL_MODIFY ON CHAIN-REQUEST.
*    endchain.
*  ENDLOOP.
*  MODULE TCNTRL_USER_COMMAND.
*&SPWIZARD: MODULE TCNTRL_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TCNTRL_CHANGE_COL_ATTR.

MODULE user_command_0102.

 

  1. Now, make coding under the MODULE PBO_102 of PBO.

IF container ISINITIAL.
g_repid = sy-repid.
g_dynnr  = sy-dynnr.
CREATEOBJECT container
EXPORTING
*           parent                      =
container_name              =  
'TEXTEDITOR1'
*            style                       =
*           lifetime                    = lifetime_default
*           repid                       =
*           dynnr                       =
*           no_autodef_progid_dynnr     =
EXCEPTIONS
cntl_error                  =
1
cntl_system_error           =
2
create_error                =
3
lifetime_error              =
4
lifetime_dynpro_dynpro_link =
5
OTHERS                      = 6
.
IF sy-subrc <> 0.
*        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

g_mycontainer =
'TEXTEDITOR1'.

CREATEOBJECT editor
EXPORTING
*           max_number_chars       =
*           style                  = 0
wordwrap_mode          =  cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position      = 
'256'
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
*           filedrop_mode          = dropfile_event_off
parent                 = container
*           lifetime               =
*           name                   =
*         EXCEPTIONS
*           error_cntl_create      = 1
*           error_cntl_init        = 2
*           error_cntl_link        = 3
*           error_dp_create        = 4
*           gui_type_not_supported = 5
*           others                 = 6
.
IF sy-subrc <> 0.
*        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

REFRESH g_mytable.

CALLMETHOD container->link
EXPORTING
repid                       =  g_repid
dynnr                       =  g_dynnr
container                   =  g_mycontainer
*    EXCEPTIONS
*      cntl_error                  = 1
*      cntl_system_error           = 2
*      lifetime_dynpro_dynpro_link = 3
*      others                      = 4
.
IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 

6. Now, the container can contains the data using the two objects of container and editor:

 

  

 

 

7. Now in PBI using the below code you can take out data from custom container and save into cluster database as coding defined below:

 

               

**& FOR SAVING OF TEXT OF CUSTOM CONTAINER &**************

CLEAR g_mytable[].

CALLMETHOD editor->get_text_as_r3table
*            EXPORTING
*              only_when_modified     = FALSE
IMPORTING
table                  =  g_mytable
*              is_modified            =
*            EXCEPTIONS
*              error_dp               = 1
*              error_cntl_call_method = 2
*              error_dp_create        = 3
*              potential_data_loss    = 4
*              others                 = 5
.
IF sy-subrc <> 0.
*           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

IF g_mytable[] ISNOTINITIAL.
CLEAR t_text.
CLEAR: text1,
len ,
len1,
text2.
LOOPAT g_mytable INTO  w_mytable.
CLEAR:w_text-tdline.
len =
STRLEN( w_mytable ).
text1 = w_mytable+
0(132).

w_text-tdline = text1.
APPEND w_text TO t_text.
CLEAR w_text.
IF len > 132.
len1 = len -
132.
text2 = w_mytable+
132(len1).

w_text-tdline = text2.
APPEND w_text TO t_text.
CLEAR w_text.
ELSE.
text2 = space.

w_text-tdline = text2.
APPEND w_text TO t_text.
CLEAR w_text.
ENDIF.

CLEAR : len1, len.
ENDLOOP.
ENDIF.
**& END FOR SAVING OF TEXT OF CUSTOM CONTAINER &**********
*          CLEAR temp2.
*          CONCATENATE tmp1 ylck-lcno INTO temp2.
indx-aedat = sy-datum.
indx-usera = sy-uname.
indx-pgmid = sy-repid.
EXPORT t_text TODATABASE indx(lc) ID v_docno.
IF sy-subrc <> 0.
MESSAGE'Document required data is not saved'TYPE'I'.
EXIT.
ELSE.
PERFORM cleardocreq.
ENDIF.
** USING OF INBUILT CLUSTER DATABASE &*************
** END OF INBUILT CLUSTER DATABSE &****************

 

 

8. At last if you want to get data from data base you want to show in custom containers you can use method as shown below:

 

**& END FOR GETING OF TEXT OF CUSTOM CONTAINER &**********
CLEAR : v_docno, j_text, t_text.
v_docno = wa_ylck-docno.
IMPORT t_text TO j_text FROMDATABASE indx(lc) ID v_docno.
IF sy-subrc <> 0.
MESSAGE'Document required data is not available'TYPE'I'.
EXIT.
ELSE.
CLEAR: text1, g_mytable, w_mytable, g_mytable[],
len,
len1,
text2.
REFRESH : g_mytable, g_mytable[].
DATAiTYPEiVALUE0.
LOOPAT j_text INTO w_text.

IFi = 0.
text1 = w_text-tdline.
CLEAR w_text.
i = i + 1.
ELSEIFi = 1.
text2 = w_text-tdline.
CONCATENATE text1 text2 INTO w_mytable.

APPEND w_mytable TO g_mytable.
i = 0.
CLEAR : w_mytable, text1, text2.
ENDIF.
ENDLOOP.

CALLMETHOD editor1->set_text_as_r3table
EXPORTING
table = g_mytable.
ENDIF.

 

                


Displaying 3D Graphs in ABAP

$
0
0

Displaying 3D Graphs in ABAP

 

*Simple report to create graph in ABAP

*using GRAPH_MATRIX_3D function module

*The graph shows the performance of 3 companies for the Four

*quarters of a single year

*AUTHOR : Swarna.S.

REPORT Z_3DGRAPH.

*structure declaration for performance measurement

TYPES: BEGIN OF ty_performance,

      company(15) TYPE c,

      q1 TYPE i,

      q2 TYPE i,

      q3 type i,

      q4 type i,

      END OF ty_performance.

*structure declaration for options table

types : BEGIN OF ty_opttable,

        options(30) TYPE c,

        END OF ty_opttable.

*Internal table and work area declarations

DATA: it_performance TYPE STANDARD TABLE OF ty_performance,

      wa_performance TYPE ty_performance.

DATA : it_opttable type standard table of ty_opttable,

       wa_opttable type ty_opttable.

*initialization event

  1. INITIALIZATION.

*start of selection event

START-OF-SELECTION.

*clearing the work areas

CLEAR WA_PERFORMANCE.

CLEAR wa_opttable.

*appending values into the performance internal table

wa_performance-company = 'Company A'.

wa_performance-q1      = 78.

wa_performance-q2      = 68.

wa_performance-q3      = 79.

wa_performance-q4      = 80.

append wa_performance to it_performance.

wa_performance-company = 'Company B'.

wa_performance-q1      = 48.

wa_performance-q2      = 68.

wa_performance-q3      = 69.

wa_performance-q4      = 70.

append wa_performance to it_performance.

wa_performance-company = 'Company C'.

wa_performance-q1      = 78.

wa_performance-q2      = 48.

wa_performance-q3      = 79.

wa_performance-q4      = 85.

append wa_performance to it_performance.

*appending values into the options internal table

wa_opttable-options = 'P3TYPE = TO'.

APPEND wa_opttable TO it_opttable.

wa_opttable-options = 'P2TYPE = VB'.

APPEND wa_opttable TO it_opttable.

wa_opttable-options = 'TISIZE = 1'.

APPEND wa_opttable TO it_opttable.

*calling the graph function module

  CALL FUNCTION 'GRAPH_MATRIX_3D'

    EXPORTING

      col1 = 'Quarter 1'

      col2 = 'Quarter 2'

      col3 = 'Quarter 3'

      col4 = 'Quarter 4'

       dim1 = 'In Percentage%'

      set_focus = 'X'

      titl = 'Company Performances'

    TABLES

      data = it_performance

      opts = it_opttable

    EXCEPTIONS

      others = 1.

 

ABAP - internal table and sorting and sum

$
0
0

Hello,

 

I am relatively new to ABAP and I am facing the following task:

 

Internal table itab with the following columns:

 

  •           VHILM LIKE VEKP-VHILM,    " Packaging material
  •          WERKS LIKE MSEG-WERKS,    " Plant
  •          LGORT LIKE MSEG-LGORT,    " Storage location
  •          LIFNR LIKE MSEG-LIFNR,    " Vendor
  •          MBLNR LIKE MKPF-MBLNR , " number of material document
  •          MJAHR LIKE MKPF-MJAHR , " posting date of material document
  •          ZEILE LIKE MSEG-ZEILE , " item in material document
  •          VENUM LIKE HUMSEG-VENUM" Handling unit
  •          SHKZG LIKE MSEG-SHKZG,
  •           MENGE TYPE ,

 

The requirement is to group entries in this table according to VHILM, WERKS, LGORT and LIFNR

and to have the SUM in MENGE.

 

Am doing the following

 

          sort itab by VHILM WERKS LGORT LIFNR.

 

 

        loop at itab into wa_itab.

 

          wa_itab2 = wa_itab.

 

     at END OF LIFNR.

 

       SUM.

       write: / , wa_itab2-LIFNR, wa_itab2-MENGE.

 

 

     endat.

 

 

   ENDLOOP.

 

But MENGE is not summed, why since it is numeric type?



FILES AND NOTE ATTACHMENTS CREATION, DISPLAY AND DELETION USING GOS SERVICES

$
0
0

STEP 1:- Use transaction SWO1 to create an generic object services.

STEP 2:- A popup appears. Fill fields Object type, Object name, Name, Description and Program. Choose Application = '*'. Leave Supertype blank.

 

 

 

 

STEP 3:- In the main page position the mouse pointer on “Interfaces” and press F5 (add object). In the popup choose interface IFGOSASERV for SAP ECC 4.7 and IFGOSXSERV for SAP ECC 6.0.

 

STEP 4:-Add key fields by position on “Key Fields” and press F5. Give table name TRDIR and press ok.

 

 

 

 

STEP 6:-Position on method GOSAddObjects under methods tab and press F6 (Redefine). Insert the following code:

 

DATA:

SERVICE(255),

BUSIDENTIFS LIKE BORIDENT OCCURS 0,

LS_BORIDENT type BORIDENT.

CLEAR LS_BORIDENT.

LS_BORIDENT-LOGSYS = SPACE.

LS_BORIDENT-OBJTYPE = 'ZGOS'.

LS_BORIDENT-OBJKEY = OBJECT-KEY.

APPEND LS_BORIDENT to BUSIDENTIFS.

SWC_GET_ELEMENT CONTAINER 'Service' SERVICE.

SWC_SET_TABLE CONTAINER 'BusIdentifs' BUSIDENTIFS.

 

Add highlighted code here

 

STEP 7:- Save and generate Business Object. Set release status to “released”

If it is causing problem then put cursor on business object then follow the path EDIT->CHANGE RELEASE STATUS->OBJECT TYPE COMPONENET->TO IMPLEMENTED.

Then save and again generate then release.

STEP 8:- In data decleration put the code below:

CONSTANTS : objtype TYPE borident-objtype VALUE'ZGOS'.

DATA: manager TYPEREFTO cl_gos_manager,
obj
TYPE borident.

Now in program add the below code in PBO where you want to use it.

  1. Examples.

IF manager ISINITIAL.
obj-objtype = objtype.
DATA : goskey(70) TYPEc.

IF zcapex-capex_no ISNOTINITIAL.

“key creation according to your requirement
CONCATENATE sy-repid '/' zcapex-capex_no INTO goskey.

      obj-objkey = goskey.

ENDIF.


IF zcapex-capex_no ISNOTINITIAL.
CREATEOBJECT manager
EXPORTING
is_object    = obj
ip_no_commit =
'R'
EXCEPTIONS
OTHERS       = 1.
ENDIF.

 

Here, goskey is the key to find the document in corresponding of particular number.

 

Many Thanks / Himanshu Gupta

workflow version transfer

$
0
0

Hi,Everybody.

 

The lastest version 001 of workflow WS20000075 in our production, and how to transfer it to development client?

Number Range Object Creation and Use

$
0
0

Creation of SAP Number Range Object,

 

SAP provides SNRO for creating also custom objects which can we use in ZY module or standard to generate automatically numbers in SAP.

 

To get the current number, use the object with the help of function module 'NUMBER_GET_NEXT'.

 

Creation of a Number range object:

  1. 1.Go to transaction SNRO (Simple way to remember isSAPNumber Range Object).

 


1.JPG

  1. 2.      Enter the number range object name and press CREATE.
  2. 3.      Enter the description, Long text and Number Length domain and Warning % as shown below:
2.JPG

Warning %  Assume that an interval is defined from 1 to 1000. If you want to issue a warning at the number 900, enter 10 (%) here.

 

4.Press SAVE. You would get a prompt as shown below:

 

3.JPG

5.      Press YES and assign the object to a local class.

 


6.Now click on “Number Ranges” button on the application toolbar.

 

4.JPG

7.      Click on “Change Intervals”.

 

5.JPG

6.JPG

8.      Click on “Insert Interval”.


9.Enter the values as shown below:

 

7.JPG

  1. 10.Click “Insert” and then SAVE. The number range object is generated.

Testing the Number Range Object:

We can use the function module, NUMBER_GET_NEXT, to get the next number of any number range object.

Following is a test program to get the next available number of the object created above:

REPORT  test.

DATA: number  TYPE  i.

CALL  FUNCTION  'NUMBER_GET_NEXT'
  
EXPORTING
      nr_range_nr =
'01'
      object    =
'ZDEMO'
  
IMPORTING
     
number  = number
  
EXCEPTIONS
      interval_not_found    =
1
      number_range_not_intern  = 
2
      object_not_found      =
3
      quantity_is_0     =
4
      quantity_is_not_1     =
5
      interval_overflow   =
6
      buffer_overflow     =
7
     
OTHERS        = 8
.
IF sy-subrc  <>  0.
   
MESSAGEID  sy-msgid TYPE sy-msgty NUMBER sy-msgno
   
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

WRITE :/ 'Next available number is: ', number.

 

Print Adobe Document from any URL link in SAP ABAP.

$
0
0

Hello,

 

Through many Blog posts and SAP help sites I found it as a challenge to print the PDF in SAP.

Part of below code can be used in many ways:

1. To save the PDF file from any URL link on some shared drive.

2. To print the PDF file from your shared drive at default printer configured at your machine.

3. To print the PDF file at the printer of your choice.

 

To save the PDF file from any URL link at shared drive you can use FM HTTP_FILE_GET.

Please look into the attached file here for more information on how to use this FM in this scenario.

 

Things to note before you use this FM:

 

URL link should not be blocked from your network.

Check your network connection settings on HTTP sites in Tcode: SICF.

While passing name of your shared drive make sure that it would contain path + <filename.pdf> and not only path.

<filename> can be any name you want to give to your file.

 

Once your file get saved on shared drive you can pick it up to get printed.

FYI we are using here ADS i.e Adobe document services to print file through Sap ABAP Coding

To get this functionality you should use method Execute of Cl_Gui_Frontend_services.

Deatils on how to use the method can be found in attached file here.

 

Just to tell you what we are doing here:

We are using Adobe document services command through this method to print the file.

We need to pass the command parameters in parameter field of method.

Also we need to pass application name as Adobe.Exe or Acrord32.Exe depending on what is installed at our system in application parameter of method.

 

For details Kindly refer the full coding attached here for your reference.

 

Code is FM created for this purpose:

 

FUNCTION zv_demo_pdf_print.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(URL) TYPE  C
*"     REFERENCE(PATH) TYPE  C
*"     REFERENCE(PRINTER) TYPE  C
*"  EXPORTING
*"     REFERENCE(STATUS) TYPE  I
*"  EXCEPTIONS
*"      CONNECT_FAILED
*"      TIMEOUT
*"      INTERNAL_ERROR
*"      DOCUMENT_ERROR
*"      TCPIP_ERROR
*"      SYSTEM_FAILURE
*"      COMMUNICATION_FAILURE
*"      CNTL_ERROR
*"      ERROR_NO_GUI
*"      BAD_PARAMETER
*"      FILE_NOT_FOUND
*"      PATH_NOT_FOUND
*"      FILE_EXTENSION_UNKNOWN
*"      ERROR_EXECUTE_FAILED
*"      SYNCHRONOUS_FAILED
*"      NOT_SUPPORTED_BY_GUI
*"      UNKNOWN_ERROR
*"----------------------------------------------------------------------

  TYPES: BEGIN OF text,
          line(1000),
         END OF text.

  DATA: response         TYPE TABLE OF text WITH HEADER LINE,
        response_headers TYPE TABLE OF text WITH HEADER LINE.
  DATA: p_application TYPE string.

*first save the file from URL
*at shared drive
   CLEAR status.
  CALL FUNCTION 'HTTP_GET_FILE'
    EXPORTING
      absolute_uri          = url
      document_path         = path
    TABLES
      request_headers       = response
      response_headers      = response_headers
    EXCEPTIONS
      connect_failed        = 1
      timeout               = 2
      internal_error        = 3
      document_error        = 4
      tcpip_error           = 5
      system_failure        = 6
      communication_failure = 7
      OTHERS                = 8.

  status = sy-subrc.
  IF status <> 0.
    CASE status.
      WHEN 1.
        RAISE connect_failed.
      WHEN 2.
        RAISE timeout.
      WHEN 3.
        RAISE internal_error.
      WHEN 4.
        RAISE document_error.
      WHEN 5.
        RAISE tcpip_error.
      WHEN 6.
        RAISE system_failure.
      WHEN 7.
        RAISE communication_failure.
      WHEN OTHERS.
        RAISE unknown_error.
    ENDCASE.
  ELSE.
*if file saved succesfully at shared path
*pick the file and print it on printer

    CONCATENATE '/t' url printer INTO p_application SEPARATED BY space.

    break amitkumar.
    CALL METHOD cl_gui_frontend_services=>execute
      EXPORTING
        application            = 'ACRORD32.EXE'
        parameter              = p_application
        minimized              = 'X'
      EXCEPTIONS
        cntl_error             = 1
        error_no_gui           = 2
        bad_parameter          = 3
        file_not_found         = 4
        path_not_found         = 5
        file_extension_unknown = 6
        error_execute_failed   = 7
        synchronous_failed     = 8
        not_supported_by_gui   = 9
        OTHERS                 = 10.
    IF sy-subrc NE 0.
      status = sy-subrc.
      CASE sy-subrc.
        WHEN 1.
          RAISE cntl_error.
        WHEN 2.
          RAISE error_no_gui.
        WHEN 3.
          RAISE bad_parameter.
        WHEN 4.
          RAISE file_not_found.
        WHEN 5.
          RAISE path_not_found.
        WHEN 6.
          RAISE file_extension_unknown.
        WHEN 7.
          RAISE error_execute_failed.
        WHEN 8.
          RAISE synchronous_failed.
        WHEN 9.
          RAISE not_supported_by_gui.
        WHEN OTHERS.
          RAISE unknown_error.
      ENDCASE.
    else.
      status = 0.
    ENDIF.

  ENDIF.

ENDFUNCTION.

 

Thanks,

Amit

ABAP Performance Analyse und Optimierung mit Manfred Mensch 08.10 - 09.10 in Regensdorf

$
0
0

Jetzt buchbar unter:

https://training.sap.com/ch/de/course/wchapt-abap-performance-tuning-seminar-classroom-010-ch-de/

 

 

Warum Sie dieses Seminar besuchen sollten

·          Lernen Sie die bewährten Werkzeuge zur Performance Analyse kennen

·          Bringen Sie sich auf den aktuellen Stand bzgl. Neuentwicklungen im Bereich der Werkzeuge

·          Lernen Sie wenig bekannte Tipps und Tricks zu den Werkzeugen kennen

·          Schauen Sie einem erfahrenen Tool-Entwickler und Performance-Experten von SAPs zentraler Performance-Gruppe bei der Performanceanalyse über die Schulter

·          Lernen und diskutieren Sie über Möglichkeiten und Methoden der Performanceanalyse

·          Lernen Sie die typischen Performance Probleme in Kundeneigenentwicklungen kennen

·          Erfahren Sie mehr über die Möglichkeiten zu Optimierung dieser typischen Performance Probleme

·          Während des Seminars gibt es Live Demonstrationen.

·          Falls Sie sich in Ihr eigenes System einwählen können: Wenden Sie das Gelernte direkt in Ihrem System an und erhalten Sie wertvolle Tipps und Hinweise. Bitte beachten Sie dabei, dass im Seminar keine exklusive Beratungsleistung erbracht werden kann.

 

Tag 1 Agenda (ABAP Performance Analyse)

·          Vorstellung und Demonstration der ABAP Performance Analyse Werkzeuge

Ø Code Inspector (SCI)

Ø Statistical Records Monitor (STAD)

Ø Performance Trace (ST05)

Ø Runtime Analysis (SE30, SAT)

Ø Weitere Tools

·          Best Practise: Analysemethoden und Benutzung der Werkzeuge

·          Übungsmöglichkeit auf Trainingssystem (bei Einwahlmöglichkeit auch auf eigenem System)

 

Tag 2 Agenda (ABAP Performance Optimierung)

·          Typische Performance Probleme und Optimierungsmöglichkeiten

    Ø Datenbankzugriffe

                Ø Tabellenpufferung

                Ø Interne Tabellen

·          Demos, Praktische Übungen, Diskussionen

·          Übungsmöglichkeit auf Trainingssystem (bei Einwahlmöglichkeit auch auf eigenem System)


How to print customer documentation in IMG as PDF

$
0
0

Hi all,

 

for our project documentation, we would like to 'print' the customer documents of an img project as a pdf file.

Is this possible and if yes: how? Is it be possible to include links to external documents as url?

 

Thanks for your suggestions, best regards, Kathrin

Obtaining current action reference for standard commands of WDA ALV component

$
0
0

When developing a WDA you can run into a problem when you need to perform different tasks depending on actual standard action the user selected. The proper place to do this is your view WDDOBEFOREACTION method. The problem is that WD runtime does not return proper reference to the IF_WD_ACTION interface for standard SALV component actions while calling back your WDDOBEFOREACTION. Namely lo_api_controller->get_current_action( ) returns null reference.

The reason why get_current_action returns nothing is that the controller of the action is not the current view controller as seen in the IF_WD_VIEW_CONTROLLER~GET_CURRENT_ACTION method:

 

method if_wd_view_controller~get_current_action.

 

   data: l_action type ref to if_wdr_action.

 

   if me->action_accessor->is_valid = abap_true.

     l_action ?= me->action_accessor->current_action.

     if l_action->controller = me.

       result = me->action_accessor->current_action.

     endif.

   else.

     raise exception type cx_wdr_rt_exception

         exporting

            textid = cx_wdr_rt_exception=>method_not_valid_for_phase

            msgv1  = 'IF_WD_VIEW_CONTROLLER~GET_CURRENT_ACTION'

            msgv2  = 'WDDOBEFOREACTION'.

   endif.

 

endmethod.

 

After some digging into the source code I found a solution. The key point  is that when you obtain a reference to the current view controller by calling

wd_this->wd_get_api method actually you receive a reference to an instance of cl_wdr_delegating_view class. I enhanced the class by adding the following method:

 

METHOD Y_GET_CURRENT_ACTION .

   IF me->action_accessor->is_valid = abap_true.

     result = me->action_accessor->current_action.

   ENDIF.

ENDMETHOD.

 

In WDDOBEFOREACTION I use the following snippet to call enhanced method:

 

   DATA lo_delegating_view TYPE REF TO cl_wdr_delegating_view.

   DATA lo_api_controller TYPE REF TO if_wd_view_controller.


   lo_api_controller = wd_this->wd_get_api( ).

   lo_delegating_view ?= lo_api_controller.


     lo_action = lo_delegating_view->y_get_current_action( ).

 

Still works.

BAPI for creating Process Order

$
0
0

Hi everybody

 

i'm looking for a BAPI to create process orders.

 

I've found the BAPI called BAPI_PROCORD_CREATE to set up the header of the process order e.g. to COR1. Unfortunately i can't find a BAPI to enter the material list and the appropriate quanity etc.

 

Is there anybody out there who has an idea?

 

Thanks in advanced

 

Thomas

ABAP program for uploading stock adjustment.

$
0
0

Process scenario : In retail IT environment there are numerous systems integrated which has seamless communication to the SAP system. Since there are dependency of data which flows from third party systems continuously into SAP, this  needs to be validated to control the type of data making it completely error free while it is received or posted to SAP system.

 

Problem :

 

Goods Movement IDOC comes from host (NON SAP) which fails due to gap in reason code mapping between  host and SAP system.


  1. Correction :

 

The only way out to correct this problem is by identifying the data from the idocs which were failed and post them into SAP via MIGO transaction code manually..

 

   2. Bottleneck :

 

The frequency of failure occurrence depends upon the data flown to SAP as idocs from third party systems. If the data is so huge the rectification via manual posting becomes tedious to get these failure documents corrected and  posted through MIGO transaction. In a  normal scenario this would require three hours / day for performing this activity.


   3. Feasible solution :

 

A mechanism to be developed to post erratic data via a custom program in SAP for bulk uploading that could handle document creations in a single stretch. And thereby reducing human effort spent to achieve correction which is currently being done manually posting them one by one.

 

This requirement could be achieved by using the  BAPI_GOODSMVT_CREATE a standard BAPI provided by SAP in a custom developed program that could cater the necessity of uploading of data. The program shown below gets the file path, row begin and row end as inputs . Here in the figure 1.1 the local file path is set along with the row begin and column begin inputs. Generally in the source file the first row would be header so row begin would be 2 and end row we could consider as 5 and varies depends on the data that is to be processed.

 

 

Fig 1.1

 

fig1.1.png

After executing the program we get the log as shown in Fig 1.2 about the successful or unsuccessful updating.

 

Fig 1.2

fig1.2.png

 

Now lets see the core coding part of the program developed. This program has minimal procedural approach at the front end but has a class lying underneath which handles the major operations of the program such as loading the source file, preliminary checks, converting the source file to the desired format to make it ready for the uploading and finally posting the documents and getting the result for display through ALV output. We will see below step by step process involved in developing the component.

 

Step1. Create a structure ZST_GOODSMVT_UPL as shown in figure 1.3.

 

Fig 1.3.

 

fig1.3.png

Create the table types :

 

ZTT_GOODSMVT_ITEM for line type BAPI2017_GM_ITEM_CREATE

ZTT_BAPIRET2 for line type BAPIRET2,

ZTT_GOODSMVT_UPL for line type ZST_GOODSMVT_UPL.

 

 

Step 2. Create a class ZCL_GOODSMVT_UPLOAD with three methods as shown below.We will see each method and its parameters in detail.

 

Figure 1.4

fig1.4.png

 

Parameters for method MAP_FILE_PATH

 

Figure 1.5

fig1.5.png

Add the below code into this method. :

 

method map_file_path.

field-symbols : &lt;ls_file&gt; type file_table.

call method cl_gui_frontend_services=>file_open_dialog
exporting
window_title            = 'Choose File to be Uploaded'
default_extension       = '.xls'
changing
file_table              = e_filetab
rc                      = lv_rc
exceptions
file_open_dialog_failed = 1
cntl_error              = 2
error_no_gui            = 3
not_supported_by_gui    = 4
others                  = 5.

if sy-subrc &lt;&gt; 0.
  message e001(zgmupl).
else.
  read table e_filetab assigning &lt;ls_file&gt;  index 1.
  if sy-subrc eq 0.
   e_filename = &lt;ls_file&gt;-filename.
  endif.
endif.

  endmethod.


Parameters for method UPLOAD_FILE.

 

Figure 1.6

fig1.6.png


After creating the parameters the below code is added to the method.

 

method upload_file.

data : lt_file  type table of kcde_cells,
ls_final type zst_goodsmvt_upl,
lr_ex    type ref to cx_root,
lv_msg   type string.


field-symbols : &lt;ls_file&gt; type kcde_cells.

clear gt_final.
call function 'KCD_EXCEL_OLE_TO_INT_CONVERT'
exporting
filename                = i_filename
i_begin_col             = i_begcol
i_begin_row             = i_begrow
i_end_col               = i_endcol
i_end_row               = i_endrow
tables
intern                  = lt_file
exceptions
inconsistent_parameters = 1
upload_ole              = 2
others                  = 3.
if sy-subrc &lt;&gt; 0.
  message e002(zgmupl).
else.
  sort lt_file by row col.

endif.

clear : e_keyid , e_fldval .
loop at lt_file assigning &lt;ls_file&gt; .

try .
case &lt;ls_file&gt;-col.

when 1.
ls_final-keyid = &lt;ls_file&gt;-value.

when 2.
ls_final-budat = &lt;ls_file&gt;-value.

when 3.

ls_final-bldat = &lt;ls_file&gt;-value.

when 4.
ls_final-bktxt = &lt;ls_file&gt;-value.

when 5.
ls_final-matnr = &lt;ls_file&gt;-value.

when 6.
ls_final-plant = &lt;ls_file&gt;-value.

when 7.
ls_final-lgort = &lt;ls_file&gt;-value.

when 8.
ls_final-bwart = &lt;ls_file&gt;-value.

  when 9.
ls_final-erfmg = &lt;ls_file&gt;-value.

when 10.
ls_final-erfme = &lt;ls_file&gt;-value.

when 11.
ls_final-sgtxt = &lt;ls_file&gt;-value.

when others.
endcase.

catch cx_root into lr_ex.

e_keyid = ls_final-keyid.
e_fldval = &lt;ls_file&gt;-value.
e_exmsg = lr_ex->get_text( ).

return.

endtry.

if &lt;ls_file&gt;-col = i_endcol.
append ls_final to gt_final.
clear ls_final.
continue.
endif.
endloop.

endmethod.


Parameters for method POST_GOODSMVT_UPLOAD.


fig1.7.png


Create the below code into the above method.

 

method post_goods_mvt.

call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header               = i_header
goodsmvt_code                 = i_code
TESTRUN                       = ' '
IMPORTING
GOODSMVT_HEADRET              e_headret
MATERIALDOCUMENT              e_matdoc
MATDOCUMENTYEAR               e_docyr
  tables
goodsmvt_item                 = i_item
return                        = e_return
.

if sy-subrc eq 0.

endif.

endmethod.

 

Now that we have created the parameters and methods, we have to create a main program to instantiate and use this class for our purpose.

 

Create a program ZMM_GOODSMVT_UPLOAD .

 

Create a top include ZMM_GOODSMVT_UPLOAD_TOP which has the global declarations.

 

TYPES : BEGIN OF ty_final.
INCLUDE STRUCTURE zst_goodsmvt_upl.
TYPES : END OF ty_final.


TYPES: BEGIN OF ty_log ,
keyid TYPE char10,
message TYPE bapi_msg,
END OF ty_log.


DATA : go_goodsmvt  TYPE REF TO zcl_goodsmvt_upload,
gt_filetab TYPE filetable,
gt_final TYPE TABLE OF ty_final,
gs_final TYPE ty_final,
  gt_log TYPE TABLE OF ty_log,
gs_log TYPE ty_log.

DATA : gv_file TYPE rlgrap-filename. " file name

DATA :    gs_header  TYPE bapi2017_gm_head_01,
gv_code    TYPE char2,
gt_item    TYPE TABLE OF bapi2017_gm_item_create,
gs_item    TYPE bapi2017_gm_item_create,
gs_headret TYPE bapi2017_gm_head_ret,
gv_matdoc  TYPE bapi2017_gm_head_ret-mat_doc,
gv_docyr   TYPE bapi2017_gm_head_ret-doc_year,
gt_return  TYPE TABLE OF bapiret2.

CONSTANTS : gc_code TYPE char2 VALUE '03'.

FIELD-SYMBOLS : &lt;gs_return&gt; TYPE bapiret2,
&lt;gs_final&gt; TYPE zst_goodsmvt_upl.


PARAMETERS : sp_file   TYPE rlgrap-filename,
sp_brow   TYPE i,
sp_bcol   TYPE i DEFAULT '1' NO-DISPLAY,
sp_erow   TYPE i,
sp_ecol   TYPE i DEFAULT '11' NO-DISPLAY.

 

 

Create another include ZMM_GOODSMVT_UPLOAD_F01.  which handles the required routines.

 

First we will have a look at the main program

and the subsequent performs we see in it are created in the include ZMM_GOODSMVT_UPLOAD_F01.

 

REPORT  zmm_goodsmvt_upload.

INCLUDE zmm_goodsmvt_upload_top.
INCLUDE zmm_goodsmvt_upload_f01.

INITIALIZATION.

AT SELECTION-SCREEN.
*--validate the max row count
PERFORM validate_rows.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_file.

CLEAR : gt_filetab,
gt_final.

CREATE OBJECT go_goodsmvt.

*--Map the file path
CALL METHOD go_goodsmvt->map_file_path
IMPORTING
e_filetab  = gt_filetab
e_filename = sp_file.

START-OF-SELECTION.
*--Upload the data from source file
PERFORM upload_data.
*--Display the output log
PERFORM display_output.

 

We will closely view each performs and the process they are assigned to carry out in the below .


Fig 1.8

fig1.8.png


For  PERFORM upload_datacreate the below code.

 

FORM upload_data .

DATA : lv_msg   TYPE char100,
lv_keyid TYPE char10,
lv_fldval TYPE char25,
lv_exmsg TYPE string.

CLEAR : gv_file, lv_keyid, lv_fldval, lv_exmsg.
gv_file = sp_file.

CREATE OBJECT go_goodsmvt.
*--Get the table values
CALL METHOD go_goodsmvt->upload_file
EXPORTING
i_filename = gv_file
i_begrow   = sp_brow
i_begcol   = sp_bcol
i_endrow   = sp_erow
i_endcol   = sp_ecol
IMPORTING
e_keyid    = lv_keyid
e_fldval   = lv_fldval
e_exmsg    = lv_exmsg
gt_final   = gt_final.
*--check for error
IF NOT lv_keyid IS INITIAL.

CLEAR lv_msg.
CONCATENATE text-011 lv_keyid text-012 lv_fldval lv_exmsg INTO
lv_msg SEPARATED BY space.
MESSAGE lv_msg TYPE 'S' DISPLAY LIKE 'E'.
RETURN.

ELSEIF  gt_final IS INITIAL.
*-- if no data found to be uploaded
MESSAGE text-009 TYPE 'S' DISPLAY LIKE 'E'.
RETURN.

ENDIF.

*--prepare for posting.
LOOP AT gt_final ASSIGNING &lt;gs_final&gt;.

CLEAR : gs_header, gs_headret, gv_matdoc,
gv_docyr, gt_return, gs_item.
*--Populate header
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external            = &lt;gs_final&gt;-budat
IMPORTING
date_internal            = gs_header-pstng_date
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.
IF sy-subrc &lt;&gt; 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external            = &lt;gs_final&gt;-bldat
IMPORTING
date_internal            = gs_header-doc_date
EXCEPTIONS
date_external_is_invalid = 1
OTHERS                   = 2.
IF sy-subrc &lt;&gt; 0.
* Implement suitable error handling here
ENDIF.

gs_header-header_txt = &lt;gs_final&gt;-bktxt.

*--Populate item
UNPACK &lt;gs_final&gt;-matnr TO gs_item-material.

gs_item-plant     = &lt;gs_final&gt;-plant.
gs_item-stge_loc  = &lt;gs_final&gt;-lgort.
gs_item-move_type = &lt;gs_final&gt;-bwart.
gs_item-entry_qnt = &lt;gs_final&gt;-erfmg.
gs_item-entry_uom = &lt;gs_final&gt;-erfme.
gs_item-item_text = &lt;gs_final&gt;-sgtxt.

APPEND gs_item TO gt_item.
CLEAR gs_item.

AT END OF keyid.
*--call the BAPI to post the document
CALL METHOD go_goodsmvt->post_goods_mvt
EXPORTING
i_header  = gs_header
i_code    = gc_code
i_item    = gt_item
i_testrun = space
IMPORTING
e_headret = gs_headret
e_matdoc  = gv_matdoc
e_docyr   = gv_docyr
e_return  = gt_return.
*--of error in posting
IF NOT gt_return IS INITIAL.

LOOP AT gt_return ASSIGNING &lt;gs_return&gt;.
*--Prepare log
gs_log-keyid = &lt;gs_final&gt;-keyid.
CONCATENATE &lt;gs_return&gt;-type &lt;gs_return&gt;-id
&lt;gs_return&gt;-number &lt;gs_return&gt;-message
INTO gs_log-message SEPARATED BY space.
APPEND gs_log TO gt_log.
CLEAR gs_log.

ENDLOOP.

ELSE.
*--for successful posting
IF NOT gs_headret-mat_doc IS INITIAL.

*--commit work and wait. " for successful posting.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*--Prepare log
gs_log-keyid = &lt;gs_final&gt;-keyid.
CONCATENATE text-003 gs_headret-mat_doc text-002
gs_headret-doc_year text-004 INTO gs_log-message
SEPARATED BY space.

APPEND gs_log TO gt_log.
CLEAR gs_log.
ENDIF.
ENDIF.
CLEAR : gs_header , gt_item, gs_headret,
gv_matdoc, gv_docyr, gt_return.

ENDAT.
ENDLOOP.
ENDFORM. " UPLOAD_DATA

 

For PERFORM display_output use the below code.

 

FORM display_output .
*
DATA: lo_alv        TYPE REF TO cl_salv_table,
lx_msg        TYPE REF TO cx_salv_msg,     
lo_layout     TYPE REF TO cl_salv_layout,
lv_functions  TYPE REF TO cl_salv_functions_list,
lv_column     TYPE REF TO cl_salv_column_list,
lv_columns    TYPE REF TO cl_salv_columns,
lo_aggrs      TYPE REF TO cl_salv_aggregations,    
lo_key_col    TYPE REF TO cl_salv_columns_table .
*
DATA: ls_key        TYPE salv_s_layout_key,
lf_variant    TYPE slis_vari.
*
CONSTANTS : lc_x    TYPE c VALUE 'X'.
*
IF NOT gt_log IS INITIAL.
*--Calling the factory method
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table      = gt_log ).
CATCH cx_salv_msg INTO lx_msg.
EXIT.
ENDTRY.
lo_layout = lo_alv->get_layout( ).
*--set Layout save restriction
ls_key-report = sy-repid.
lo_layout->set_key( ls_key ).
lo_layout->set_save_restriction(           if_salv_c_layout=>restrict_none ).
*--set initial Layout
lf_variant = 'DEFAULT'.
lo_layout->set_initial_layout( lf_variant ).
*--activate ALV generic Functions
lv_functions = lo_alv->get_functions( ).
lv_functions->set_all( lc_x ).
lv_columns = lo_alv->get_columns( ).
lv_columns->set_optimize( lc_x ).
lo_aggrs = lo_alv->get_aggregations( ).
lo_key_col = lo_alv->get_columns( ).
lo_key_col->set_optimize( lc_x ).
lo_key_col->set_key_fixation( 'X' ).
*--visible columns
TRY.

lv_column ?= lv_columns->get_column( text-005 ).
lv_column->set_short_text( text-006 ).
lv_column->set_medium_text( text-006 ).
lv_column->set_long_text( text-006 ).

lv_column ?= lv_columns->get_column( text-007 ).
lv_column->set_short_text( text-008 ).
lv_column->set_medium_text( text-008 ).
lv_column->set_long_text( text-008 ).

CATCH cx_salv_not_found.
EXIT.
ENDTRY.
lo_alv->display( ).
ENDIF.
*
ENDFORM. " DISPLAY_LOG

 

These text elements are created

Fig 1.9

fig1.9.png

 

Selection texts created.

Figure 2.0


fig2.0.png

Source File format :


Key ID,

posting date

doc date,

header text,

Material,

plant,

storage,

Mov type,

entry qty,

UOM,

Item text

 

Maintain the source file as mentioned in the above format in the excel file. The first column Key ID serves as an identifier to combine the line items into a single document.

 

Scalability :

 

Though this class has been created specifically to cater the goods adjustment upload, this could  be further enhanced by adding appropriate new fields to the structure , adding new methods to take it into a complete object oriented pattern design and can be used for  uploading data related to goods movement.



 

 

 




 

 

 

 

 

 

 

 

 

 

 

 

 

.

FRIENDSHIP in OOABAP

$
0
0

Everyone knows what exactly a friendship is and how its is used.

#used ???

I mean in OOABAP how it is used  ..... We are in SCN so most of us know what exactly I am talking about ; this blog is exclusively for the people who are new to this topic. Lets not waste much time just scan through. A sample code is also written, keeping in mind that this topic would be much crisp and clear.

Following the SAP K.I.S.S way.(Keep It Short and Simple)


1.Friendship between classes:-

A Class can grant friendship to another class. By granting friendship, it allows another class to:-

  • Use its private components.
  • Instatiate it, irrespective of the CREATE PRIVATE addition.

 

Ex:-

1. Class C2 is created using CREATE PRIVATE option. That means only the class itself and its friends can instantiate this class.

2. Class C2 has a private method M2 and a private attribute, NUM. This means that these components can be accessed by class C2          itself and its friends.

3. Now C2 has granted friendship to class C1.

4. So, methods of class C1 can access private components of C2 as well as can instantiate class C2.

 

Program:-

 

CLASS C1 DEFINITION DEFERRED.

 

CLASS C2 DEFINITION CREATE PRIVATE FRIENDS C1.

    PROTECTED SECTION.

       DATA: NUM TYPE I VALUE 5.

       METHODS : M2.

ENDCLASS.

 

CLASS C2 IMPLEMENTATION.

   METHOD M2.

      WRITE:/5 'I am method M2 in C2'.

    ENDMETHOD.

ENDCLASS.

 

CLASS C1 DEFINITION.

    PUBLIC SECTION.

     METHODS: M1.

ENDCLASS.

 

CLASS C1 IMPLEMENTATION.

   METHOD M1.

    DATA: OREF2 TYPE REF TO C2.

    CREATE OBJECT OREF2.

    WRITE:/5 OREF2->NUM.

    CALL METHOD OREF2->M2.

    ENDMETHOD.

ENDCLASS.

 

START-OF-SELECTION.

 

   DATA: OREF1 TYPE REF TO C1.

   CREATE OBJECT OREF1.

   CALL METHOD OREF1->M1.

 

Output:-

5

I am method M2 in C2.

 

 

2.Subclasses of friends can also become friends:-

Subclasses of the friend class are also friends of the class granting friendship (to their super classes).

 

Ex:-

1. Class C2 has granted friendship to class C1. Hence, C1 is friend of class C2.

2. Class C11 is a sub class of class C1.

3. So, class C11 is also a friend of class C2. Class C11 can thus access the protected components of class C2.

 

Program:-

 

CLASS C1 DEFINITION DEFERRED.

 

CLASS C2 DEFINITION FRIENDS C1.

      PROTECTED SECTION.

       DATA: NUM TYPE I VALUE 5.

ENDCLASS.

 

CLASS C2 IMPLEMENTATION.

ENDCLASS.

 

CLASS C1 DEFINITION.

    PUBLIC SECTION.

      METHODS: M1.

ENDCLASS.

 

CLASS C1 IMPLEMENTATION.

      METHOD M1.

           DATA: OREF2 TYPE REF TO C2.

           CREATE OBJECT OREF2.

           WRITE:/5 OREF2->NUM.

       ENDMETHOD.

ENDCLASS.

 

CLASS C11 DEFINITION INHERITING FROM C1.

    PUBLIC SECTION.

      METHODS: M11.

ENDCLASS.

 

CLASS C11 IMPLEMENTATION.

      METHOD M11.

         DATA: OREF2 TYPE REF TO C2.

         CREATE OBJECT OREF2.

         WRITE:/5 OREF2->NUM.

       ENDMETHOD.

ENDCLASS.

 

START-OF-SELECTION.

 

DATA: OREF11 TYPE REF TO C11.

CREATE OBJECT OREF11.

CALL METHOD OREF11->M11.

Output:-

5

 

3.Friendship is one sided:-

In principle, granting of friendship is one-sided: A class granting a friendship is not automatically a friend of its friends. If the class granting the friendship wants to access the private components of a friend, then the latter has to explicitly grant friendship to the former.


Ex:-

1. Class C2 grants friendship to class C1. Hence, class C1 can access protected attribute (num2) of C2.

2. But, Class C2 cannot access protected attribute (num1) of class C1. This is because friendship is one-sided.

3. To allow C2 access protected attribute of C1, class C1 must also declare C2 as its friend.

 

Program:-

 

Let us do the incorrect way first

 

Wrong way:-

 

CLASS C1 DEFINITION DEFERRED.

CLASS C2 DEFINITION FRIENDS C1.
PROTECTED SECTION.
DATA:NUM2 TYPE I VALUE 15.
METHODS: M2.
ENDCLASS.

CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS:METHPUB.
PRIVATE SECTION.
DATA: NUM1 TYPE I VALUE 10.
METHODS: M1.
ENDCLASS.

CLASS C2 IMPLEMENTATION.
METHOD  M2.
DATA: OREF1 TYPE REF TO C1.
CREATE OBJECT OREF1.
WRITE:/5 OREF1->NUM1.
ENDMETHOD.
ENDCLASS.

CLASS C1 IMPLEMENTATION.
METHOD M1.
DATA: OREF2 TYPE REF TO C2.
CREATE OBJECT OREF2.
WRITE:/5 OREF2->NUM2.
ENDMETHOD.

METHOD METHPUB.
CALL METHOD M1.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

DATA: OREF TYPE REF TO C1.
CREATE OBJECT OREF.
CALL METHOD OREF->METHPUB.

 

Output:-ERROR:Access to private attribute “NUM1” is not allowed.

 

This is what happens if you dont offer friendship

 

Correct way:-

 

CLASS C1 DEFINITION DEFERRED.

CLASS C2 DEFINITION FRIENDS C1.
PROTECTED SECTION.
DATA:NUM2 TYPE I VALUE 15.
METHODS: M2.
ENDCLASS.

CLASS C1 DEFINITION FRIENDS C2.
PUBLIC SECTION.
METHODS:METHPUB.
PRIVATE SECTION.
DATA: NUM1 TYPE I VALUE 10.
METHODS: M1.
ENDCLASS.

CLASS C2 IMPLEMENTATION.
METHOD  M2.
DATA: OREF1 TYPE REF TO C1.
CREATE OBJECT OREF1.
WRITE:/5 OREF1->NUM1.
ENDMETHOD.
ENDCLASS.

CLASS C1 IMPLEMENTATION.
METHOD M1.
DATA: OREF2 TYPE REF TO C2.
CREATE OBJECT OREF2.
WRITE:/5 OREF2->NUM2.
ENDMETHOD.

METHOD METHPUB.
CALL METHOD M1.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

DATA: OREF TYPE REF TO C1.
CREATE OBJECT OREF.
CALL METHOD OREF->METHPUB.

 

Output:-

15

Create scheme from DDIC

$
0
0

Did you ever had the need of creating a xml scheme out of DDIC tables/structures ?

 

I was searching in google for some ideas as this should be a quite common problem. But most of the solutions ended up in too much coding (using functions from function group SDIXML)

 

Indeed there seems to be a quite short solution using the ECATT implementation which by nature faces the same problems in a even wider variety:

 

 

 

These few lines will create a scheme for the table BKPF exporting it to a string:

 

 

 

Please take this short peace of code as opportunity to play around with all the other parameters and helper methods.

 

In case the ECATT classes do not fit all your needs you can still chosse the function group SDIXML. You will find a quite comprehensive example in the article of Sanjay Badhai following this link.

USE CUSTOM CONTAINER FOR MULTIPLE LINE DISPLAY AND SAVE

$
0
0

Hiii,

 

This document used to get know how to use custom container to make an multiple lines editable text box...

 

INTRODUCTION: Use a custom container to get multiple text data from file, or by writing and to save data in cluster database.

Steps:

  1. Make a custom container in sceen.
  2. Make object of cl_gui_cutom container.
  3. Make object of cl_gui_textedit.
  4. Use method of class cl_gui_textedit to link subsceen container to main sceen subsceen area and to use it.
  5. Use set_text_as_r3table to set data in custom_container and use get_text_as_r3table to get data from custom_container to internal table.

Advantage:

  1. Use of objects.
  2. Use of cluster database to save data. So to increase speed and save database space also using INDX database of cluster database.
  3. Can able to get data from any document into our custom container.
  4. Can able to make document using text in custom container.
  5. Save multiple line data in the database.

Step-by-step

  1. First make a tab in which use a sub screen subl_doc for calling of sceen contains of custom container.

 

 

 

 

2. Second step make a sceen on which use a custom container name as TEXTEDITOR1.

 

  

 

 

3. Define the object refrences in top part of calling screen using below coding:

 

   

CONSTANTS texte TYPE n LENGTH 5VALUE256.

DATA: editor TYPEREFTO cl_gui_textedit,
container
TYPEREFTO cl_gui_custom_container.

DATA  g_repid TYPE sy-repid.
DATA  g_dynnr TYPE sy-dynnr.
DATA  g_mytable(256) TYPEcOCCURS0.
DATA  t_text TYPESTANDARDTABLEOF tline.
DATA  j_text TYPESTANDARDTABLEOF tline.
DATA  w_text TYPE tline.
DATA  w_mytable(texte) TYPEc .
CLASS cl_gui_cfw DEFINITIONLOAD. "to load class
DATA  v_docno(22).
DATA i_docno TYPE n LENGTH 22.
DATA: text1(132),
len
TYPEi,
len1
TYPEi,
text2(
132).

  1. Now call this sub screen using the below coding in main sceen:


PROCESS BEFORE
OUTPUT.
module clear_syucomm.

CALL SUBSCREEN subl_mat INCLUDING 'YEXPORT_PROCES''0104'.
CALL SUBSCREEN subl_bak INCLUDING 'YEXPORT_PROCES''0105'.
CALL SUBSCREEN subl_doc INCLUDING 'YEXPORT_PROCES''0106'.“sub screen calling for                                                             “ custom container

*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TCNTRL'
*  MODULE TCNTRL_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TCNTRL_CHANGE_COL_ATTR.
*  LOOP AT   IT_YLCP
*       WITH CONTROL TCNTRL
*       CURSOR TCNTRL-CURRENT_LINE.
***    MODULE TCNTRL_GET_LINES.
**&SPWIZARD:   MODULE TCNTRL_CHANGE_FIELD_ATTR
*  ENDLOOP.

MODULE status_0102.
*
MODULE PBO_102.      “Use to make objects for custom container

PROCESS AFTER
INPUT.

MODULE exit_prog_102 ATEXIT-COMMAND.


call SUBSCREEN subl_mat.
call SUBSCREEN subl_bak.
call SUBSCREEN subl_doc.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TCNTRL'
*  LOOP AT IT_YLCP.
*    CHAIN.
*      FIELD IT_YLCP-SRLNO.
*      FIELD IT_YLCP-MATNR.
*      FIELD IT_YLCP-MAKTX.
*      FIELD IT_YLCP-LCMAKTX.
*      FIELD IT_YLCP-VRKME.
*      FIELD IT_YLCP-FKIMG.
*      FIELD IT_YLCP-kurrf.
*      FIELD IT_YLCP-DMBTR.
*      MODULE TCNTRL_MODIFY ON CHAIN-REQUEST.
*    endchain.
*  ENDLOOP.
*  MODULE TCNTRL_USER_COMMAND.
*&SPWIZARD: MODULE TCNTRL_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TCNTRL_CHANGE_COL_ATTR.

MODULE user_command_0102.

 

  1. Now, make coding under the MODULE PBO_102 of PBO.

IF container ISINITIAL.
g_repid = sy-repid.
g_dynnr  = sy-dynnr.
CREATEOBJECT container
EXPORTING
*           parent                      =
container_name              =  
'TEXTEDITOR1'
*            style                       =
*           lifetime                    = lifetime_default
*           repid                       =
*           dynnr                       =
*           no_autodef_progid_dynnr     =
EXCEPTIONS
cntl_error                  =
1
cntl_system_error           =
2
create_error                =
3
lifetime_error              =
4
lifetime_dynpro_dynpro_link =
5
OTHERS                      = 6
.
IF sy-subrc <> 0.
*        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

g_mycontainer =
'TEXTEDITOR1'.

CREATEOBJECT editor
EXPORTING
*           max_number_chars       =
*           style                  = 0
wordwrap_mode          =  cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position      = 
'256'
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
*           filedrop_mode          = dropfile_event_off
parent                 = container
*           lifetime               =
*           name                   =
*         EXCEPTIONS
*           error_cntl_create      = 1
*           error_cntl_init        = 2
*           error_cntl_link        = 3
*           error_dp_create        = 4
*           gui_type_not_supported = 5
*           others                 = 6
.
IF sy-subrc <> 0.
*        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

REFRESH g_mytable.

CALLMETHOD container->link
EXPORTING
repid                       =  g_repid
dynnr                       =  g_dynnr
container                   =  g_mycontainer
*    EXCEPTIONS
*      cntl_error                  = 1
*      cntl_system_error           = 2
*      lifetime_dynpro_dynpro_link = 3
*      others                      = 4
.
IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 

6. Now, the container can contains the data using the two objects of container and editor:

 

  

 

 

7. Now in PBI using the below code you can take out data from custom container and save into cluster database as coding defined below:

 

               

**& FOR SAVING OF TEXT OF CUSTOM CONTAINER &**************

CLEAR g_mytable[].

CALLMETHOD editor->get_text_as_r3table
*            EXPORTING
*              only_when_modified     = FALSE
IMPORTING
table                  =  g_mytable
*              is_modified            =
*            EXCEPTIONS
*              error_dp               = 1
*              error_cntl_call_method = 2
*              error_dp_create        = 3
*              potential_data_loss    = 4
*              others                 = 5
.
IF sy-subrc <> 0.
*           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

IF g_mytable[] ISNOTINITIAL.
CLEAR t_text.
CLEAR: text1,
len ,
len1,
text2.
LOOPAT g_mytable INTO  w_mytable.
CLEAR:w_text-tdline.
len =
STRLEN( w_mytable ).
text1 = w_mytable+
0(132).

w_text-tdline = text1.
APPEND w_text TO t_text.
CLEAR w_text.
IF len > 132.
len1 = len -
132.
text2 = w_mytable+
132(len1).

w_text-tdline = text2.
APPEND w_text TO t_text.
CLEAR w_text.
ELSE.
text2 = space.

w_text-tdline = text2.
APPEND w_text TO t_text.
CLEAR w_text.
ENDIF.

CLEAR : len1, len.
ENDLOOP.
ENDIF.
**& END FOR SAVING OF TEXT OF CUSTOM CONTAINER &**********
*          CLEAR temp2.
*          CONCATENATE tmp1 ylck-lcno INTO temp2.
indx-aedat = sy-datum.
indx-usera = sy-uname.
indx-pgmid = sy-repid.
EXPORT t_text TODATABASE indx(lc) ID v_docno.
IF sy-subrc <> 0.
MESSAGE'Document required data is not saved'TYPE'I'.
EXIT.
ELSE.
PERFORM cleardocreq.
ENDIF.
** USING OF INBUILT CLUSTER DATABASE &*************
** END OF INBUILT CLUSTER DATABSE &****************

 

 

8. At last if you want to get data from data base you want to show in custom containers you can use method as shown below:

 

**& END FOR GETING OF TEXT OF CUSTOM CONTAINER &**********
CLEAR : v_docno, j_text, t_text.
v_docno = wa_ylck-docno.
IMPORT t_text TO j_text FROMDATABASE indx(lc) ID v_docno.
IF sy-subrc <> 0.
MESSAGE'Document required data is not available'TYPE'I'.
EXIT.
ELSE.
CLEAR: text1, g_mytable, w_mytable, g_mytable[],
len,
len1,
text2.
REFRESH : g_mytable, g_mytable[].
DATAiTYPEiVALUE0.
LOOPAT j_text INTO w_text.

IFi = 0.
text1 = w_text-tdline.
CLEAR w_text.
i = i + 1.
ELSEIFi = 1.
text2 = w_text-tdline.
CONCATENATE text1 text2 INTO w_mytable.

APPEND w_mytable TO g_mytable.
i = 0.
CLEAR : w_mytable, text1, text2.
ENDIF.
ENDLOOP.

CALLMETHOD editor1->set_text_as_r3table
EXPORTING
table = g_mytable.
ENDIF.

 

                


BAPI_ACC_DOCUMENT_POST for posting F-47

$
0
0

For the F-47 posting, it only post to 1 line item whereby BAPI "BAPI_ACC_DOCUMENT_POST" have to post in 2 lines for balance the account. Here are the steps to do posting F-47 (Down Payment Request) via BAPI with 1 line item.

 

1) Create a new function group using transaction code SE80.

 

2) Copy the standard function module of BTE "SAMPLE_INTERFACE_RWBAPI01" to a Z Function module, say "ZSAMPLE_INTERFACE_RWBAPI01"

 

3) Goto transaction code FIBF to create the BTE for process "RWBAPI01".

    Refer the link at Configuration session - Business Transaction Event - RWBAPI01 - For Accounting Document Interface - ABAP Development - SCN Wiki

 

4) Before call the BAPI "BAPI_ACC_DOCUMENT_POST", prepare the table for extension1 as below:

 

  DEFINE mac_assign_extension.

    clear lv_string.

    concatenate &1 &2

       into lv_string.

    concatenate &3 lv_string

           into &3

      separated by ';'.

  END-OF-DEFINITION.

 

*-> prepare extension

    CONCATENATE '0001' ls_accountpayable-itemno_acc

           INTO ls_extension1-field1.   " 0001 => running number for different purpose to triggering BTE "RWBAPI01"

    CONCATENATE 'BSTAT' 'S'  INTO ls_extension1-field2.

    mac_assign_extension 'BSCHL' '39' ls_extension1-field2.

    mac_assign_extension 'UMSKZ' 'F' ls_extension1-field2.

    mac_assign_extension 'ZUMSK' 'Z' ls_extension1-field2.

    mac_assign_extension 'SHKZG' 'H' ls_extension1-field2.

    APPEND ls_extension1 TO lt_extension1.

 

5) In the function module "ZSAMPLE_INTERFACE_RWBAPI01", read the table extension1 and populate the field into table IT_ACCIT.

 

  TYPES : BEGIN OF ty_extension,

            field TYPE char50,

          END OF ty_extension.

 

 

  TYPES : tty_extension TYPE STANDARD TABLE OF ty_extension.

 

 

  DATA : ls_extension TYPE bapiacextc,

         ws_extension TYPE ty_extension,

         lt_extension TYPE tty_extension,

         lv_tabix     TYPE sytabix,

         lv_len       TYPE i.

 

 

  DATA : lv_bstat TYPE char01,

         lv_bschl TYPE char01,

         lv_umskz TYPE char01,

         lv_zumsk TYPE char01,

         lv_shkzg TYPE char01.

 

 

  DEFINE mac_assign_value.

    clear lv_len.

    if &4 is initial.

      find first occurrence of &1 in &2 match length lv_len.

      if sy-subrc = 0.

        &3 = &2+lv_len.

        &4 = 'X'.

      endif.

    endif.

  END-OF-DEFINITION.

 

 

  LOOP AT extension INTO ls_extension.

    CASE ls_extension-field1(4).

      WHEN '0001'.  "For down payment request

        MOVE 'RFST' TO document_header-glvor.

 

 

        READ TABLE it_accit WITH KEY posnr = ls_extension-field1+4(10).

        IF sy-subrc = 0.

          lv_tabix = sy-tabix.

          SPLIT ls_extension-field2 AT ';'

           INTO TABLE lt_extension

             IN CHARACTER MODE.

          LOOP AT lt_extension INTO ws_extension.

            mac_assign_value 'BSTAT' ws_extension-field it_accit-bstat lv_bstat.

            mac_assign_value 'BSCHL' ws_extension-field it_accit-bschl lv_bschl.

            mac_assign_value 'UMSKZ' ws_extension-field it_accit-umskz lv_umskz.

            mac_assign_value 'ZUMSK' ws_extension-field it_accit-zumsk lv_zumsk.

            mac_assign_value 'SHKZG' ws_extension-field it_accit-shkzg lv_shkzg.

          ENDLOOP.

 

          MODIFY it_accit INDEX lv_tabix.

        ENDIF.

      WHEN OTHERS.

    ENDCASE.

  ENDLOOP.

 

IDOC for Post Goods Issue for Return Delivery

$
0
0


Hi experts,

 

I would like to know how to post goods issue for return delivery using IDOC?

 

I tried to use IDOC DELVRY03, and get stuck with handling units (packing information). But in my return delivery, packing is not requirement.

 

Can any one please advise? Thanks.

Field exits, hints to use them

$
0
0

I have used field exits since several years ago and I have had some nightmares with them also

 

Then I want to share some hints about field-exit uses:

 

 

1. What is a data type ?

 

 

In my personal opinion, the purpose of data types is misunderstood and undervalued by many ABAP programmers.

 

This is specially true when programmers only develop for one country and do not need translations (example: you develop for a company working in Spain, then you define the titles only in spanish but if you are developing for a multinational company you MUST define titles in several languages). The use of data type for internationalization is very valuable.

 

In this thinking line, data types have "semantic" in the sense that they helps to provide meaning to entities (type of data) created and living within the ABAP workspace.

 

Another point is: data types create standardization within the system. Every time a field is created using a data type, the field get the same characteristics and meaning of any other field created using the same data type.

 

Finally, the obvious: data type helps to verify and control data quality and data restrictions (through domains, off course).

 

2. Why field exits ?

 

Each field exit works attached to a data type.

 

Field exits go one step further in data quality management. It is possible to implement complex data checking via field exits or data checking that depend on the specific dynpro (transaction), user, etc.

 

3. What can not be done via field exit ?

 

Field exits have some limits by design:

 

a. Field exit only can issue an error message, not warning and not informative messages.

 

It has not sense informing that the data input is correct but it has sense only to inform when the data is incorrect.

 

b. Field exit can not retrieve some environment information

 

As far as I know, a field exit CAN obtain general information from the system (sy- variables) but it can not obtain information about the programm/transaction variables. Field exit purpose is to verify input values alone.

 

It is possible to use some tricks to transfer information from outside to the field exit (set parameter, for example) but, in my experience, these tricks easily fails (and the field exit could cause problems).

 

4 Some hints

 

a. Grouping

 

It is a good idea creating functions groups dedicated only to field exits. These groups must contain no more than 5 field exits or so in order to make them manageable. Off course, grouping must reflect some criteria: field exits created within a certain development project, field exits related with certain business functionality, etc.

 

b. Scope

 

It is a bad idea (very bad ) assigning "global" scope to a field exit, the consequences could be a general problem because the data type could be used in several different transactions.

 

It is possible to perform an analysis using "where used references" in ABAP workbench but, in general, this analysis would be very time consuming and it is, by far, better to assign the field exit only to selected dynpros.

 

Another point about scope: refreshing a field exit to implement a change in it (when transporting to a productive system in line) seams to have a bigger delay when the field exit is working in many dynpros and sometimes the refresh must be forced (there is a standard report to force the refresh).

 

I hope this reflections would help you programmers to understand and use successfully field exits as a powerful and helpful tool.

ABAP Resources

$
0
0

Check out ABAP resources for developers including learning materials, sites, books, videos, and other resources.

 

Learning Material for Beginners
Advanced Learning Material
Sites
Videos

Books

Additional Resources

Como identificar Caracter Especial hexadecimal - How To Identify Special Character hexadecimal

$
0
0

Como identificar Caracter Especial hexadecimal.

 

Foi vista a necessidade de recuperar o valor em hexadecimal referente ao caracter oculto #, possui o valor em hexadecimal = 23.

 

Pode ser utilizado ( ASSIGN c TO <fi> CASTING TYPE x ) para recuperar o valor em Hexa.

ScreenShot.jpg

Viewing all 29 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>