• ABAP Programs For Learners


     

    simple alv total

    REPORT zdemo_alvgrid .

    type-pools: slis.
    *Data Declaration
    data: BEGIN OF itab occurs 0,
    F1 TYPE I,
    F2 TYPE I,
    F3 TYPE I,
    END OF itab.

    data: it_fieldcatalog type slis_t_fieldcat_alv ,
    wa_fieldcatalog type slis_fieldcat_alv,
    gd_layout type slis_layout_alv,
    gd_repid like sy-repid.

    itab-f1 = '1'.
    itab-f2 = '10'.
    itab-f3 = '1234'.
    append itab.

    itab-f1 = '2'.
    itab-f2 = '400'.
    itab-f3 = '4321'.
    append itab.

    itab-f1 = '3'.
    itab-f2 = '5120'.
    itab-f3 = '0766'.
    append itab.

    itab-f1 = '4'.
    itab-f2 = '620'.
    itab-f3 = '3245'.
    append itab.

    itab-f1 = '5'.
    itab-f2 = '9430'.
    itab-f3 = '564'.
    append itab.

    itab-f1 = '6'.
    itab-f2 = '1098'.
    itab-f3 = '14'.
    append itab.

    itab-f1 = '7'.
    itab-f2 = '140'.
    itab-f3 = '4325'.
    append itab.


    wa_fieldcatalog-fieldname = 'F1'.
    wa_fieldcatalog-reptext_ddic = 'field1'.
    append wa_fieldcatalog to it_fieldcatalog .
    clear wa_fieldcatalog .

    wa_fieldcatalog-fieldname = 'F2'.
    wa_fieldcatalog-reptext_ddic = 'field2'.
    wa_fieldcatalog-do_sum = 'X'.
    append wa_fieldcatalog to it_fieldcatalog .
    clear wa_fieldcatalog .

    wa_fieldcatalog-fieldname = 'F3'.
    wa_fieldcatalog-reptext_ddic = 'field3'.
    wa_fieldcatalog-do_sum = 'X'.
    append wa_fieldcatalog to it_fieldcatalog .
    clear wa_fieldcatalog .

    * gd_layout-
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-totals_text = 'Totals'.

    gd_repid = sy-repid.

    call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
    i_callback_program = gd_repid
    is_layout = gd_layout
    it_fieldcat = it_fieldcatalog[]
    tables
    t_outtab = itab .

    simple interactive report

    REPORT zintractive .

    TYPES : BEGIN OF str_mard,
    matnr TYPE mard-matnr,
    lgort TYPE mard-lgort,
    werks TYPE mard-werks,
    END OF str_mard.
    DATA : wa_mard TYPE str_mard,
    it_mard TYPE TABLE OF str_mard.
    TYPES : BEGIN OF str_makt,
    matnr TYPE makt-matnr,
    maktg TYPE makt-maktg,
    END OF str_makt.
    DATA : wa_makt TYPE str_makt,
    it_makt TYPE TABLE OF str_makt.

    TYPES : BEGIN OF str_mara,
    matnr TYPE mara-matnr,
    ersda TYPE mara-ersda,
    ernam TYPE mara-ernam,
    laeda TYPE mara-laeda,
    mtart TYPE mara-mtart,
    matkl TYPE mara-matkl,
    meins TYPE mara-meins,
    END OF str_mara.

    DATA : wa_mara TYPE str_mara,
    it_mara TYPE TABLE OF str_mara.

    TYPES : BEGIN OF str_final,
    matnr TYPE mara-matnr,
    ersda TYPE mara-ersda,
    ernam TYPE mara-ernam,
    laeda TYPE mara-laeda,
    mtart TYPE mara-mtart,
    matkl TYPE mara-matkl,
    meins TYPE mara-meins,
    lgort TYPE mard-lgort,
    werks TYPE mard-werks,
    END OF str_final.

    DATA: wa_final TYPE str_final,
    it_final TYPE TABLE OF str_final.

    PARAMETERS : plant TYPE mard-werks,
    stor LIKE mard-lgort.


    SELECT matnr
    lgort
    werks
    FROM mard
    INTO TABLE it_mard
    WHERE lgort = stor AND werks = plant.

    .SELECT matnr
    maktg
    FROM makt
    INTO TABLE it_makt
    FOR ALL ENTRIES IN it_mard
    WHERE matnr = it_mard-matnr
    AND spras = 'E'.

    SELECT matnr
    ersda
    ernam
    laeda
    mtart
    matkl
    meins
    FROM mara
    INTO TABLE it_mara
    FOR ALL ENTRIES IN it_makt
    WHERE matnr = it_makt-matnr.

    LOOP AT it_makt INTO wa_makt.
    WRITE : /1 wa_makt-matnr COLOR 1,
    40 wa_makt-maktg COLOR 2.
    HIDE wa_makt-matnr.
    ENDLOOP.

    CLEAR wa_mard-matnr.

    AT LINE-SELECTION.
    REFRESH it_final.
    CLEAR wa_final.
    ULINE.
    IF sy-lsind = 1.
    WRITE : /1 'MATERIAL NO' COLOR 2,
    20 'CREATION DATE' COLOR 3,
    32 'PERSON CREATED',
    50 'DATE OF LIST' ,
    65 'MATERIALTYPE',
    80 'MATGROUP' ,
    90 'UNITOFMEASURE',
    110 'STORLOCATION' COLOR 4,
    130 'PLANT' COLOR 5.
    ULINE.
    ENDIF.

    LOOP AT it_mara INTO wa_mara WHERE matnr = wa_makt-matnr.
    wa_final-matnr = wa_mara-matnr.
    wa_final-ersda = wa_mara-ersda.
    wa_final-ernam = wa_mara-ernam.
    wa_final-laeda = wa_mara-laeda.
    wa_final-mtart = wa_mara-mtart.
    wa_final-matkl = wa_mara-matkl.
    wa_final-meins = wa_mara-meins.

    READ TABLE it_mard INTO wa_mard WITH KEY matnr = wa_makt-matnr.
    wa_final-lgort = wa_mard-lgort.
    wa_final-werks = wa_mard-werks.
    APPEND wa_final TO it_final.
    ENDLOOP.

    LOOP AT it_final INTO wa_final.
    WRITE :
    /1 wa_final-matnr
    COLOR 2,
    20 wa_final-ersda ,
    37 wa_final-ernam,
    50 wa_final-laeda ,
    70 wa_final-mtart ,
    85 wa_final-matkl ,
    95 wa_final-meins,
    115 wa_final-lgort ,
    130 wa_final-werks .
    ENDLOOP.

    TOP-OF-PAGE.
    WRITE : /1 'MATERIAL NO' COLOR 1,
    40 'DISCRIPTION' COLOR 2.
    ULINE .

    deleting, inserting, updating a record from work area

    report .

    data: begin of itab occurs 0,
    name(10) type c,
    age type i,
    end of itab .
    selection-screen begin of line .
    parameters:p_wa(100) type c .
    selection-screen end of line .
    selection-screen skip 2.
    selection-screen begin of line .
    SELECTION-SCREEN:
    PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
    PUSHBUTTON 15(20) but2 USER-COMMAND cli2 ,
    PUSHBUTTON 40(20) but3 USER-COMMAND cli3 visible length 5 .

    selection-screen end of line .

    at selection-screen .

    case sy-ucomm .

    when 'CLI1'.
    itab-name = p_wa+0(10) .
    itab-age = p_wa+11(2).
    append itab.

    when 'CLI2'.
    delete itab where name = p_wa+0(10) .

    when 'CLI3'.
    read table itab with key name = p_wa+0(10).
    if sy-subrc = 0.

    modify itab transporting name age.
    else .
    exit.
    endif .

    endcase .


    start-of-selection .

    loop at itab.
    write:/ itab-name .
    endloop.

    user exit for a transaction

    REPORT z_find_userexit NO STANDARD PAGE HEADING.

    TABLES : tstc, "SAP Transaction Codes
    tadir, "Directory of Repository Objects
    modsapt, "SAP Enhancements - Short Texts
    modact, "Modifications
    trdir, "System table TRDIR
    tfdir, "Function Module
    enlfdir, "Additional Attributes for Function Modules
    tstct. "Transaction Code Texts

    *&---------------------------------------------------------------------*
    *& Variables
    *&---------------------------------------------------------------------*
    DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
    DATA : field1(30).
    DATA : v_devclass LIKE tadir-devclass.

    *&---------------------------------------------------------------------*
    *& Selection Screen Parameters
    *&---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK a01.

    *&---------------------------------------------------------------------*
    *& Start of main program
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.

    * Validate Transaction Code
    SELECT SINGLE * FROM tstc
    WHERE tcode EQ p_tcode.
    * Find Repository Objects for transaction code
    IF sy-subrc EQ 0.
    SELECT SINGLE * FROM tadir
    WHERE pgmid = 'R3TR'
    AND object = 'PROG'
    AND obj_name = tstc-pgmna.
    MOVE : tadir-devclass TO v_devclass.
    IF sy-subrc NE 0.
    SELECT SINGLE * FROM trdir
    WHERE name = tstc-pgmna.
    IF trdir-subc EQ 'F'.
    SELECT SINGLE * FROM tfdir
    WHERE pname = tstc-pgmna.
    SELECT SINGLE * FROM enlfdir
    WHERE funcname = tfdir-funcname.
    SELECT SINGLE * FROM tadir
    WHERE pgmid = 'R3TR'
    AND object = 'FUGR'
    AND obj_name = enlfdir-area.
    MOVE : tadir-devclass TO v_devclass.
    ENDIF.
    ENDIF.
    * Find SAP Modifactions
    SELECT * FROM tadir
    INTO TABLE jtab
    WHERE pgmid = 'R3TR'
    AND object = 'SMOD'
    AND devclass = v_devclass.
    SELECT SINGLE * FROM tstct
    WHERE sprsl EQ sy-langu
    AND tcode EQ p_tcode.
    FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
    WRITE:/(19) 'Transaction Code - ',
    20(20) p_tcode,
    45(50) tstct-ttext.
    SKIP.
    IF NOT jtab[] IS INITIAL.
    WRITE:/(95) sy-uline.
    FORMAT COLOR COL_HEADING INTENSIFIED ON.
    WRITE:/1 sy-vline,
    2 'Exit Name',
    21 sy-vline ,
    22 'Description',
    95 sy-vline.
    WRITE:/(95) sy-uline.

    LOOP AT jtab.
    SELECT SINGLE * FROM modsapt
    WHERE sprsl = sy-langu AND
    name = jtab-obj_name.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    WRITE:/1 sy-vline,
    2 jtab-obj_name HOTSPOT ON,
    21 sy-vline ,
    22 modsapt-modtext,
    95 sy-vline.
    ENDLOOP.
    WRITE:/(95) sy-uline.
    DESCRIBE TABLE jtab.
    SKIP.
    FORMAT COLOR COL_TOTAL INTENSIFIED ON.
    WRITE:/ 'No of Exits:' , sy-tfill.
    ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(95) 'No User Exit exists'.
    ENDIF.
    ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(95) 'Transaction Code Does Not Exist'.
    ENDIF.
    * Take the user to SMOD for the Exit that was selected.
    AT LINE-SELECTION.
    GET CURSOR FIELD field1.
    CHECK field1(4) EQ 'JTAB'.
    SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
    CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

    email simple program

    REPORT ZMAIL.

    TABLES: ekko.

    PARAMETERS: p_email TYPE somlreci1-receiver .

    TYPES: BEGIN OF t_ekpo,
    ebeln TYPE ekpo-ebeln,
    ebelp TYPE ekpo-ebelp,
    aedat TYPE ekpo-aedat,
    matnr TYPE ekpo-matnr,
    END OF t_ekpo.

    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
    wa_ekpo TYPE t_ekpo.

    TYPES: BEGIN OF t_charekpo,
    ebeln(10) TYPE c,
    ebelp(5) TYPE c,
    aedat(8) TYPE c,
    matnr(18) TYPE c,
    END OF t_charekpo.

    DATA: wa_charekpo TYPE t_charekpo.

    DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
    WITH HEADER LINE.

    DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
    WITH HEADER LINE.

    DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
    t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    w_cnt TYPE i,
    w_sent_all(1) TYPE c,
    w_doc_data LIKE sodocchgi1,
    gd_error TYPE sy-subrc,
    gd_reciever TYPE sy-subrc.

    *START_OF_SELECTION

    START-OF-SELECTION.
    * Retrieve sample data from table ekpo
    PERFORM data_retrieval.

    * Populate table with detaisl to be entered into .xls file
    PERFORM build_xls_data_table.

    *END-OF-SELECTION
    END-OF-SELECTION.

    * Populate message body text
    perform populate_email_message_body.

    * Send file by email as .xls speadsheet
    PERFORM send_file_as_email_attachment
    tables it_message
    it_attach
    using p_email
    'Example .xls documnet attachment'
    'XLS'
    'filename'
    ' '
    ' '
    ' '
    changing gd_error
    gd_reciever.

    * Instructs mail send program for SAPCONNECT to send email(rsconn01)
    PERFORM initiate_mail_execute_program.
    *&---------------------------------------------------------------------*
    *& Form DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    * Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    FORM data_retrieval.
    SELECT ebeln ebelp aedat matnr
    UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
    ENDFORM. " DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    *& Form BUILD_XLS_DATA_TABLE
    *&---------------------------------------------------------------------*
    * Build data table for .xls document
    *----------------------------------------------------------------------*
    FORM build_xls_data_table.
    data: ld_store(50) type c. "Leading zeros

    CONSTANTS: con_cret(5) TYPE c VALUE '0D', "OK for non Unicode
    con_tab(5) TYPE c VALUE '09'. "OK for non Unicode

    CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED
    BY con_tab.

    CONCATENATE con_cret it_attach INTO it_attach.

    APPEND it_attach.

    LOOP AT it_ekpo INTO wa_charekpo.
    concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
    wa_charekpo-ebelp '")' into ld_store .
    CONCATENATE wa_charekpo-ebeln ld_store wa_charekpo-aedat
    wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach INTO it_attach.
    APPEND it_attach.
    ENDLOOP.
    ENDFORM. " BUILD_XLS_DATA_TABLE
    *&---------------------------------------------------------------------*
    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT
    *&---------------------------------------------------------------------*
    * Send email
    *----------------------------------------------------------------------*
    FORM send_file_as_email_attachment tables pit_message
    pit_attach
    using p_email
    p_mtitle
    p_format
    p_filename
    p_attdescription
    p_sender_address
    p_sender_addres_type
    changing p_error
    p_reciever.


    DATA: ld_error TYPE sy-subrc,
    ld_reciever TYPE sy-subrc,
    ld_mtitle LIKE sodocchgi1-obj_descr,
    ld_email LIKE somlreci1-receiver,
    ld_format TYPE so_obj_tp ,
    ld_attdescription TYPE so_obj_nam ,
    ld_attfilename TYPE so_obj_des ,
    ld_sender_address LIKE soextreci1-receiver,
    ld_sender_address_type LIKE soextreci1-adr_typ,
    ld_receiver LIKE sy-subrc.

    ld_email = p_email.
    ld_mtitle = p_mtitle.
    ld_format = p_format.
    ld_attdescription = p_attdescription.
    ld_attfilename = p_filename.
    ld_sender_address = p_sender_address.
    ld_sender_address_type = p_sender_addres_type.


    * Fill the document data.
    w_doc_data-doc_size = 1.

    * Populate the subject/generic message attributes
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle .
    w_doc_data-sensitivty = 'F'.

    * Fill the document data and get size of attachment
    CLEAR w_doc_data.
    READ TABLE it_attach INDEX w_cnt.
    w_doc_data-doc_size =
    ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle.
    w_doc_data-sensitivty = 'F'.
    CLEAR t_attachment.
    REFRESH t_attachment.
    t_attachment[] = pit_attach[].

    * Describe the body of the message
    CLEAR t_packing_list.
    REFRESH t_packing_list.
    t_packing_list-transf_bin = space.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 0.
    t_packing_list-body_start = 1.
    DESCRIBE TABLE it_message LINES t_packing_list-body_num.
    t_packing_list-doc_type = 'RAW'.
    APPEND t_packing_list.

    * Create attachment notification
    t_packing_list-transf_bin = 'X'.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 1.
    t_packing_list-body_start = 1.

    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
    t_packing_list-doc_type = ld_format.
    t_packing_list-obj_descr = ld_attdescription.
    t_packing_list-obj_name = ld_attfilename.
    t_packing_list-doc_size = t_packing_list-body_num * 255.
    APPEND t_packing_list.

    * Add the recipients email address
    CLEAR t_receivers.
    REFRESH t_receivers.
    t_receivers-receiver = ld_email.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    APPEND t_receivers.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = w_doc_data
    put_in_outbox = 'X'
    sender_address = ld_sender_address
    sender_address_type = ld_sender_address_type
    commit_work = 'X'
    IMPORTING
    sent_to_all = w_sent_all
    TABLES
    packing_list = t_packing_list
    contents_bin = t_attachment
    contents_txt = it_message
    receivers = t_receivers
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.

    * Populate zerror return code
    ld_error = sy-subrc.

    * Populate zreceiver return code
    LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
    ENDLOOP.
    ENDFORM.


    *&---------------------------------------------------------------------*
    *& Form INITIATE_MAIL_EXECUTE_PROGRAM
    *&---------------------------------------------------------------------*
    * Instructs mail send program for SAPCONNECT to send email.
    *----------------------------------------------------------------------*
    FORM initiate_mail_execute_program.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
    ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM


    *&---------------------------------------------------------------------*
    *& Form POPULATE_EMAIL_MESSAGE_BODY
    *&---------------------------------------------------------------------*
    * Populate message body text
    *----------------------------------------------------------------------*
    form populate_email_message_body.
    REFRESH it_message.
    it_message = 'Please find attached a list test ekpo records'.
    APPEND it_message.
    endform. " POPULATE_EMAIL_MESSAGE_BODY

    simple alv interactive

    REPORT ZPURCHASE_ORDER.
    *--type pools
    TYPE-POOLS:SLIS.
    *--internal tables for alv
    DATA:
    W_EBELN TYPE EKKO-EBELN,
    W_PROG TYPE SY-REPID,
    T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
    T_EVENTCAT TYPE SLIS_T_EVENT,
    W_EVENTCAT LIKE LINE OF T_EVENTCAT.

    DATA:
    T_EKKO LIKE STANDARD TABLE OF EKKO,
    FS_EKKO LIKE LINE OF T_EKKO.

    DATA:T_EKPO LIKE STANDARD TABLE OF EKPO,
    FS_EKPO LIKE LINE OF T_EKPO.

    *---- SELECT-OPTIONS DECLARATION
    SELECT-OPTIONS:S_EBELN FOR W_EBELN.

    *----- START-OF-SELECTION
    START-OF-SELECTION.
    SELECT *
    FROM EKKO
    INTO TABLE T_EKKO
    WHERE EBELN IN S_EBELN.

    W_PROG = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    I_CALLBACK_USER_COMMAND = 'PICK'
    I_STRUCTURE_NAME = 'EKKO'
    TABLES
    T_OUTTAB = T_EKKO .

    *&--------------------------------------------------------------------*
    *& Form pick
    *---------------------------------------------------------------------*
    FORM PICK USING COMMAND LIKE SY-UCOMM
    SELFIELD TYPE SLIS_SELFIELD.
    READ TABLE T_EKKO INTO FS_EKKO INDEX SELFIELD-TABINDEX.

    CASE COMMAND.
    WHEN '&IC1'.
    SELECT *
    FROM EKPO
    INTO TABLE T_EKPO
    WHERE EBELN EQ FS_EKKO-EBELN.

    W_PROG = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    I_STRUCTURE_NAME = 'EKPO'
    CHANGING
    CT_FIELDCAT = T_FIELDCAT .


    DELETE T_FIELDCAT WHERE FIELDNAME EQ 'EBELN'.
    DELETE T_FIELDCAT WHERE FIELDNAME EQ 'BUKRS'.
    DELETE T_FIELDCAT WHERE FIELDNAME EQ 'LGORT'.
    DELETE T_FIELDCAT WHERE FIELDNAME EQ 'WERKS'.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    IT_FIELDCAT = T_FIELDCAT
    IT_EVENTS = T_EVENTCAT
    TABLES
    T_OUTTAB = T_EKPO .

    ENDCASE. " CASE COMMAND
    ENDFORM. " FORM PICK

    FORM T_EVENTCAT.
    W_EVENTCAT-NAME = 'TOP_OF_PAGE'.
    W_EVENTCAT-FORM = 'TOP'.
    APPEND W_EVENTCAT TO T_EVENTCAT.
    ENDFORM.

    FORM TOP.
    READ TABLE T_EKPO INTO FS_EKPO INDEX 1.
    WRITE:/ 'Purchase Document Number'(001),30 FS_EKPO-EBELN,
    / 'Company Code'(002), 30 FS_EKPO-BUKRS,
    / 'Plant'(003), 30 FS_EKPO-WERKS,
    / 'Storage Location'(004),30 FS_EKPO-LGORT.
    ENDFORM.

    time difference between two dates

    REPORT ztest.

    DATA : lv_seconds TYPE sytabix .

    data: l type i ,
    j(10) type c ,
    k(12) type c .

    parameters:p_date1 type sy-datum,
    p_date2 type sy-datum.

    CALL FUNCTION 'SWI_DURATION_DETERMINE'
    EXPORTING
    start_date = p_date1
    end_date = p_date2
    start_time = sy-uzeit
    end_time = sy-uzeit
    IMPORTING
    duration = lv_seconds.

    l = lv_seconds.
    j = l / 60 .
    k = l / 3600 .

    WRITE :/ k ,'hours' .
    write:/ j , 'minutes' .
    write:/ l ,'seconds' .

    day month year (month in words input sy-datum)

    report ztest .

    DATA ldate(20).
    CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'
    EXPORTING
    input = sy-datum
    IMPORTING
    OUTPUT = ldate.

    write:/ ldate .

    select with cursor statement

    REPORT ZTEST_DWBLD1.

    data: it_ekko like ekko occurs 5 with header line.

    data: v_aedat type sy-datum.
    DATA: dbcur TYPE cursor.

    start-of-selection.

    v_aedat = '20001102'.

    OPEN CURSOR dbcur FOR
    select * from ekko where aedat = '20001102'.

    do.
    FETCH NEXT CURSOR dbcur INTO table it_ekko package size 5.

    if sy-subrc <> 0.
    close cursor dbcur.
    exit.
    else.

    loop at it_ekko.
    write: / it_ekko-ebeln.
    endloop.
    refresh it_ekko.
    endif.
    enddo.

    colors in alv

    REPORT zdemo_alvgrid .

    TABLES: ekko.

    type-pools: slis. "ALV Declarations

    *Data Declaration
    TYPES: BEGIN OF t_ekko,
    ebeln TYPE ekpo-ebeln,
    ebelp TYPE ekpo-ebelp,
    statu TYPE ekpo-statu,
    aedat TYPE ekpo-aedat,
    matnr TYPE ekpo-matnr,
    menge TYPE ekpo-menge,
    meins TYPE ekpo-meins,
    netpr TYPE ekpo-netpr,
    peinh TYPE ekpo-peinh,
    line_color(4) type c, "Used to store row color attributes
    END OF t_ekko.

    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
    wa_ekko TYPE t_ekko.

    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
    gd_tab_group type slis_t_sp_group_alv,
    gd_layout type slis_layout_alv,
    gd_repid like sy-repid.

    *Start-of-selection.
    START-OF-SELECTION.

    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.

    *&---------------------------------------------------------------------*
    *& Form BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    * Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    form build_fieldcatalog.

    fieldcatalog-fieldname = 'EBELN'.
    fieldcatalog-seltext_m = 'Purchase Order'.
    fieldcatalog-col_pos = 0.
    fieldcatalog-outputlen = 10.
    fieldcatalog-emphasize = 'X'.
    fieldcatalog-key = 'X'.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'EBELP'.
    fieldcatalog-seltext_m = 'PO Item'.
    fieldcatalog-col_pos = 1.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'STATU'.
    fieldcatalog-seltext_m = 'Status'.
    fieldcatalog-col_pos = 2.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'AEDAT'.
    fieldcatalog-seltext_m = 'Item change date'.
    fieldcatalog-col_pos = 3.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MATNR'.
    fieldcatalog-seltext_m = 'Material Number'.
    fieldcatalog-col_pos = 4.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MENGE'.
    fieldcatalog-seltext_m = 'PO quantity'.
    fieldcatalog-col_pos = 5.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MEINS'.
    fieldcatalog-seltext_m = 'Order Unit'.
    fieldcatalog-col_pos = 6.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'NETPR'.
    fieldcatalog-seltext_m = 'Net Price'.
    fieldcatalog-col_pos = 7.
    fieldcatalog-outputlen = 15.
    fieldcatalog-datatype = 'CURR'.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'PEINH'.
    fieldcatalog-seltext_m = 'Price Unit'.
    fieldcatalog-col_pos = 8.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.
    endform. " BUILD_FIELDCATALOG


    *&---------------------------------------------------------------------*
    *& Form BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    * Build layout for ALV grid report
    *----------------------------------------------------------------------*
    form build_layout.
    gd_layout-no_input = 'X'.
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-totals_text = 'Totals'(201).
    gd_layout-info_fieldname = 'LINE_COLOR'.
    endform. " BUILD_LAYOUT

    *&---------------------------------------------------------------------*
    *& Form DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    * Display report using ALV grid
    *----------------------------------------------------------------------*
    form display_alv_report.
    gd_repid = sy-repid.
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    i_callback_program = gd_repid
    is_layout = gd_layout
    it_fieldcat = fieldcatalog[]
    i_save = 'X'
    tables
    t_outtab = it_ekko .

    endform. " DISPLAY_ALV_REPORT


    *&---------------------------------------------------------------------*
    *& Form DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    * Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    form data_retrieval.
    data: ld_color(1) type c.

    select ebeln ebelp statu aedat matnr menge meins netpr peinh
    up to 10 rows
    from ekpo
    into table it_ekko.

    *Populate field with color attributes
    loop at it_ekko into wa_ekko.
    ld_color = ld_color + 1.
    * Only 7 colours so need to reset color value
    if ld_color = 8.
    ld_color = 1.
    endif.
    concatenate 'C' ld_color '10' into wa_ekko-line_color.
    modify it_ekko from wa_ekko.
    endloop.
    endform. " DATA_RETRIEVAL

    amount to words

    data: word(40) type c.

    CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
    EXPORTING
    AMT_IN_NUM = '10000078'
    IMPORTING
    AMT_IN_WORDS = word.

    write:/ word.

    add time to date

    report .

    data: i_date like SY-DATUM ,
    date like SY-DATUM .

    i_date = sy-datum .

    CALL FUNCTION 'ADD_TIME_TO_DATE'
    EXPORTING
    I_IDATE = i_date "Original date
    I_TIME = '1' " Ammount to add
    I_IPRKZ = '3' " unit: 'blank'-days 1-weeks 2-months 3-years
    * I_RDMHD =
    IMPORTING
    O_IDATE = date ."new date

    write:/ date .

    simple alv grid with save layout

    REPORT ZTEST.

    TYPE-POOLS: slis.

    DATA: report_id LIKE sy-repid.

    DATA: i_qmel LIKE qmel OCCURS 0.

    DATA: i_layout TYPE slis_layout_alv.

    SELECT * FROM qmel INTO TABLE i_qmel.

    report_id = sy-repid.

    PERFORM f1000_layout_init CHANGING i_layout.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = report_id
    i_structure_name = 'QMEL'
    is_layout = i_layout
    i_save = 'A'
    TABLES
    t_outtab = i_qmel .

    FORM f1000_layout_init USING
    i_layout TYPE slis_layout_alv.
    CLEAR i_layout.

    i_layout-colwidth_optimize = 'X'.

    ENDFORM.

    last day of month for fny month

    report ztest .

    data:lv_actual_date type sy-datum,
    lv_end_of_month_date type sy-datum.

    parameters:p_date type dats.

    lv_actual_date = p_date.

    CALL FUNCTION 'FIMA_DATE_CREATE'
    EXPORTING
    I_DATE = lv_actual_date
    * I_FLG_END_OF_MONTH = ' '
    * I_YEARS = 0
    * I_MONTHS = 0
    * I_DAYS = 0
    * I_CALENDAR_DAYS = 0
    I_SET_LAST_DAY_OF_MONTH = 'X'
    IMPORTING
    E_DATE = lv_end_of_month_date .

    write: / lv_end_of_month_date.

    month and year f4 help

    REPORT ZPOPDATE.

    DATA: V_CODE LIKE SY-SUBRC.

    PARAMETER: V_MONTH LIKE ISELLIST-MONTH.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR V_MONTH.

    CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
    EXPORTING
    ACTUAL_MONTH = '200205'
    LANGUAGE = SY-LANGU
    START_COLUMN = 8
    START_ROW = 5
    IMPORTING
    SELECTED_MONTH = V_MONTH
    RETURN_CODE = V_CODE
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    MONTH_NOT_FOUND = 3
    OTHERS = 4.

    program to open a file on the pc

    REPORT ZUM_OPEN_WORD .

    * The internal table is declared of size 3
    DATA: BEGIN OF ITAB OCCURS 3,
    LINE(50),
    END OF ITAB.

    PARAMETERS: PROG(70) DEFAULT
    'C:\Program Files\Microsoft Office\Office\WINWORD.EXE'.
    PARAMETERS: FILE1(70) DEFAULT 'C:\TEMP\TEST.TXT'.
    * Tick to print the Text file after saving from MS WORDS
    PARAMETERS: S_UP AS CHECKBOX.
    * Tick to create new or overwrite Text file
    PARAMETERS: S_NEW AS CHECKBOX.

    IF S_UP = 'X'.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    FILENAME = 'FILE1'
    TABLES
    DATA_TAB = ITAB
    EXCEPTIONS
    FILE_OPEN_ERROR = 1.

    IF SY-SUBRC = 0.
    LOOP AT ITAB.
    WRITE: / ITAB.
    ENDLOOP.
    ELSE.
    WRITE: / 'File open error.'.
    ENDIF.
    ELSE.
    IF S_NEW = 'X'.
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    FILENAME = 'FILE1'
    TABLES
    DATA_TAB = ITAB
    EXCEPTIONS
    FILE_WRITE_ERROR = 1
    NO_BATCH = 2
    GUI_REFUSE_FILETRANSFER = 3
    INVALID_TYPE = 4
    OTHERS = 5.
    ENDIF.
    CASE SY-SUBRC.
    WHEN 1.
    WRITE: / 'GUI DOWNLOAD FILE WRITE ERROR'.
    WHEN 2.
    WRITE: / 'GUI DOWNLOAD NO BATCH'.
    WHEN 3.
    WRITE: / 'GUI DOWNLOAD GUI REFUSE FILETRANSFER'.
    WHEN 4.
    WRITE: / 'GUI DOWNLOAD INVALID TYPE'.
    WHEN 5.
    WRITE: / 'GUI DOWNLOAD OTHERS'.
    ENDCASE.

    CALL FUNCTION 'WS_EXECUTE'
    EXPORTING
    PROGRAM = PROG
    COMMANDLINE = 'FILE1'
    INFORM = ' '
    EXCEPTIONS
    FRONTEND_ERROR = 1
    NO_BATCH = 2
    PROG_NOT_FOUND = 3
    ILLEGAL_OPTION = 4
    GUI_REFUSE_EXECUTE = 5
    OTHERS = 6.

    CASE SY-SUBRC.
    WHEN 1.
    WRITE: / 'FRONTEND ERROR'.
    WHEN 2.
    WRITE: / 'NO BATCH'.
    WHEN 3.
    WRITE: / 'PROGRAM NOT FOUND'.
    WHEN 4.
    WRITE: / 'ILLEGA OPTION'.
    WHEN 5.
    WRITE: / 'GUI REFUSE EXECUTE'.
    WHEN 6.
    WRITE: / 'OTHERS'.
    ENDCASE.
    ENDIF.

    number in words

    report ztest .

    parameters: v_int TYPE i .

    DATA words LIKE SPELL.

    CALL FUNCTION 'SPELL_AMOUNT'
    EXPORTING
    AMOUNT = v_int
    LANGUAGE = SY-LANGU
    IMPORTING
    IN_WORDS = words
    .
    WRITE words-word.

    month in words (input date)

    REPORT ZMONTH.

    DATA X_MONTH(11).

    parameters:p_date type sy-datum.


    CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'
    EXPORTING
    INPUT = p_date
    IMPORTING
    OUTPUT = X_MONTH.

    WRITE:/ 'Month ', X_MONTH+3(8).

    modify itab

    report ztest .

    tables:mara,marc,mard.
    data:begin of it_final occurs 0,
    matnr like mara-matnr,
    mtart like mara-mtart,
    meins like mara-meins,
    werks like marc-werks,
    pstat like marc-pstat,
    lgort like mard-lgort,
    labst like mard-labst,
    end of it_final.

    select-options:s_matnr for mara-matnr.
    start-of-selection.
    select matnr
    mtart
    meins
    from mara
    into table it_final
    where matnr in s_matnr.
    if sy-subrc = 0.
    loop at it_final.
    select single
    werks
    pstat
    from marc
    into (it_final-werks,it_final-pstat)
    where matnr = it_final-matnr.
    modify it_final.
    if sy-subrc = 0.
    select single
    lgort
    labst
    from mard
    into (it_final-lgort,it_final-labst)
    where werks = it_final-werks.
    modify it_final.
    endif.
    endloop.
    endif.

    if sy-subrc = 0.
    loop at it_final.
    write:/ it_final-matnr,
    it_final-mtart,
    it_final-meins,
    it_final-werks,
    it_final-pstat,
    it_final-lgort,
    it_final-labst.
    endloop.
    endif.

    lbd with out macros

    REPORT ZTEST .

    TABLES pernr.

    INFOTYPES : 0001.

    START-OF-SELECTION.

    GET pernr.

    WRITE : / 'Result from Macros'.

    rp-provide-from-frst p0001 space pn-begda pn-endda.

    IF pnp-sw-found = 1.

    WRITE : / '-------------------------------------'.

    WRITE : / 'Result from rp-provide-from-frst'.

    WRITE : / '-------------------------------------'.

    WRITE : / p0001-pernr, p0001-begda, p0001-endda.

    ENDIF.

    rp-provide-from-last p0001 space pn-begda pn-endda.

    IF pnp-sw-found = 1.

    WRITE : / '-------------------------------------'.

    WRITE : / 'Result from rp-provide-from-last'.

    WRITE : / '-------------------------------------'.

    WRITE : / p0001-pernr, p0001-begda, p0001-endda.

    ENDIF.

    rp-read-infotype pernr-pernr 0001 p0001 pn-begda pn-endda.

    IF pnp-sw-found = 1.

    WRITE : / '-------------------------------------'.

    WRITE : / 'Result from rp-read-infotype'.

    WRITE : / '-------------------------------------'.

    LOOP AT p0001.

    WRITE : / p0001-pernr, p0001-begda, p0001-endda.

    ENDLOOP.

    ENDIF.

    END-OF-SELECTION.

    list box from user values

    report ztest.

    TYPE-POOLS: VRM.
    DATA: NAME TYPE VRM_ID,
    LIST TYPE VRM_VALUES,
    VALUE LIKE LINE OF LIST.

    PARAMETERS: PS_PARM(10) AS LISTBOX VISIBLE LENGTH 10.

    AT SELECTION-SCREEN OUTPUT.

    NAME = 'PS_PARM'.
    VALUE-KEY = '1'.
    VALUE-TEXT = 'LINE 1'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '2'.
    VALUE-TEXT = 'LINE 2'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '3'.
    VALUE-TEXT = 'LINE 3'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '4'.
    VALUE-TEXT = 'LINE 4'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '5'.
    VALUE-TEXT = 'LINE 5'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '6'.
    VALUE-TEXT = 'LINE 6'.
    APPEND VALUE TO LIST.

    VALUE-KEY = '7'.
    VALUE-TEXT = 'LINE 7'.
    APPEND VALUE TO LIST.

    CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
    ID = NAME
    VALUES = LIST.

    START-OF-SELECTION.
    WRITE: / 'PARAMETER:', PS_PARM.

    simple ldb report

    TABLES:PERNR.
    INFOTYPES:0002,0008.
    GET PERNR.
    PROVIDE * FROM P0002 BETWEEN PN-BEGDA AND PN-ENDDA.
    ENDPROVIDE.
    PROVIDE * FROM P0008 BETWEEN PN-BEGDA AND PN-ENDDA.
    ENDPROVIDE.

    IF SY-SUBRC = 0.
    WRITE:/ P0002-PERNR,
    P0002-BEGDA,
    P0002-ENDDA,
    P0002-VORNA,
    P0008-ANSAL,
    P0008-lga01,
    P0008-bet01,
    P0008-PREAS.
    ENDIF.

    simple inner jion

    REPORT ZTEST .
    tables:mara,marc,mard.
    data:begin of itab occurs 0,
    matnr like mara-matnr,
    mtart like mara-mtart,
    meins like mara-meins,
    werks like marc-werks,
    pstat like marc-pstat,
    labst like mard-labst,
    lgort like mard-lgort,
    maktx like makt-maktx,
    end of itab.


    select-options:s_matnr for mara-matnr.

    start-of-selection.
    select a~matnr
    a~mtart
    a~meins
    b~werks
    b~pstat
    c~lgort
    c~labst
    into corresponding fields of table itab
    from mara as a inner join marc as b on a~matnr = b~matnr
    inner join mard as c on a~matnr = c~matnr
    and b~werks = c~werks
    where a~matnr in s_matnr.

    if sy-subrc = 0.
    loop at itab.
    select single maktx
    from makt
    into itab-maktx
    where matnr = itab-matnr.
    modify itab.

    write:/ itab-matnr,
    itab-mtart,
    itab-meins,
    itab-werks,
    itab-pstat,
    itab-lgort,
    itab-labst,
    itab-maktx.
    endloop.

    user exit in a program

    REPORT ztest .
    TABLES : TSTC,
    TADIR,
    MODSAPT,
    MODACT,
    TRDIR,
    TFDIR,
    ENLFDIR,
    SXS_ATTRT ,
    TSTCT.

    DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.
    DATA : FIELD1(30).
    DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.

    PARAMETERS : P_TCODE LIKE TSTC-TCODE,
    P_PGMNA LIKE TSTC-PGMNA .




    DATA wa_tadir type tadir.

    START-OF-SELECTION.

    IF NOT P_TCODE IS INITIAL.
    SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.

    ELSEIF NOT P_PGMNA IS INITIAL.
    TSTC-PGMNA = P_PGMNA.
    ENDIF.

    IF SY-SUBRC EQ 0.
    SELECT SINGLE * FROM TADIR
    WHERE PGMID = 'R3TR'
    AND OBJECT = 'PROG'
    AND OBJ_NAME = TSTC-PGMNA.

    MOVE : TADIR-DEVCLASS TO V_DEVCLASS.

    IF SY-SUBRC NE 0.
    SELECT SINGLE * FROM TRDIR
    WHERE NAME = TSTC-PGMNA.
    IF TRDIR-SUBC EQ 'F'.
    SELECT SINGLE * FROM TFDIR
    WHERE PNAME = TSTC-PGMNA.

    SELECT SINGLE * FROM ENLFDIR
    WHERE FUNCNAME = TFDIR-FUNCNAME.

    SELECT SINGLE * FROM TADIR
    WHERE PGMID = 'R3TR'
    AND OBJECT = 'FUGR'
    AND OBJ_NAME EQ ENLFDIR-AREA.

    MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
    ENDIF.
    ENDIF.

    SELECT * FROM TADIR INTO TABLE JTAB
    WHERE PGMID = 'R3TR'
    AND OBJECT in ('SMOD', 'SXSD')
    AND DEVCLASS = V_DEVCLASS.


    SELECT SINGLE * FROM TSTCT
    WHERE SPRSL EQ SY-LANGU
    AND TCODE EQ P_TCODE.

    FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
    WRITE:/(19) 'Transaction Code - ',
    20(20) P_TCODE,
    45(50) TSTCT-TTEXT.
    SKIP.
    IF NOT JTAB[] IS INITIAL.
    WRITE:/(105) SY-ULINE.
    FORMAT COLOR COL_HEADING INTENSIFIED ON.

    * Sorting the internal Table
    sort jtab by OBJECT.
    data : wf_txt(60) type c,
    wf_smod type i ,
    wf_badi type i ,
    wf_object2(30) type C.
    clear : wf_smod, wf_badi , wf_object2.
    * Get the total SMOD.




    LOOP AT JTAB into wa_tadir.
    at first.
    FORMAT COLOR COL_HEADING INTENSIFIED ON.

    WRITE:/1 SY-VLINE,
    2 'Enhancement/ Business Add-in',
    41 SY-VLINE ,
    42 'Description',
    105 SY-VLINE.
    WRITE:/(105) SY-ULINE.
    endat.
    clear wf_txt.
    at new object.
    if wa_tadir-object = 'SMOD'.
    wf_object2 = 'Enhancement' .
    elseif wa_tadir-object = 'SXSD'.
    wf_object2 = ' Business Add-in'.

    endif.
    FORMAT COLOR COL_GROUP INTENSIFIED ON.

    WRITE:/1 SY-VLINE,

    2 wf_object2,
    105 SY-VLINE.
    endat.

    case wa_tadir-object.
    when 'SMOD'.
    wf_smod = wf_smod + 1.
    SELECT SINGLE MODTEXT into wf_txt
    FROM MODSAPT
    WHERE SPRSL = SY-LANGU
    AND NAME = wa_tadir-OBJ_NAME.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

    when 'SXSD'.
    * For BADis
    wf_badi = wf_badi + 1 .
    select single TEXT into wf_txt
    from SXS_ATTRT
    where sprsl = sy-langu
    and EXIT_NAME = wa_tadir-OBJ_NAME.
    FORMAT COLOR COL_NORMAL INTENSIFIED ON.

    endcase.



    WRITE:/1 SY-VLINE,
    2 wa_tadir-OBJ_NAME hotspot on,
    41 SY-VLINE ,
    42 wf_txt,
    105 SY-VLINE.
    AT END OF object.
    write : /(105) sy-ULINE.
    ENDAT.


    ENDLOOP.

    WRITE:/(105) SY-ULINE.



    SKIP.
    FORMAT COLOR COL_TOTAL INTENSIFIED ON.
    WRITE:/ 'No.of Exits:' , wf_smod.
    WRITE:/ 'No.of BADis:' , wf_badi.

    ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(105) 'No userexits or BADis exist'.
    ENDIF.
    ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(105) 'Transaction does not exist'.
    ENDIF.

    AT LINE-SELECTION.

    data : wf_object type tadir-object.
    clear wf_object.

    GET CURSOR FIELD FIELD1.
    CHECK FIELD1(8) EQ 'WA_TADIR'.
    read table jtab with key obj_name = sy-lisel+1(20).
    move jtab-object to wf_object.

    case wf_object.
    when 'SMOD'.
    SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).

    CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
    when 'SXSD'.
    SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20).
    CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
    endcase.

    itab to excel or txt file( using f4_file)

    TABLES : MARA.

    *-------------INTERNAL TABLE DECLARATION
    TYPES : BEGIN OF ITAB,
    MATNR TYPE MARA-MATNR,
    MEINS TYPE MARA-MEINS,
    ERNAM LIKE MARA-ERNAM,
    AENAM LIKE MARA-AENAM,
    MTART LIKE MARA-MTART,
    END OF ITAB.

    DATA : IG_ITAB type ITAB OCCURS 0.
    DATA : V_FILE TYPE STRING.
    DATA : T_FILE TYPE RLGRAP-FILENAME.

    *-------------RETRIVE DATA FROM DATABASE
    SELECT
    MATNR
    MEINS ERNAM AENAM MTART FROM MARA
    INTO CORRESPONDING FIELDS OF TABLE
    IG_ITAB
    up to 10 rows.


    *-------------CALLING FUNCTION MODULES
    CALL FUNCTION 'F4_FILENAME' "PASS THE FILE NAME AS U NEED.
    EXPORTING
    FIELD_NAME = 'T_FILE'
    IMPORTING
    FILE_NAME = T_FILE.

    V_FILE = T_FILE. "STRING CONVERSION

    *-------------CALLING GUI DOWNLOAD TO EXTRACT
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = V_FILE
    FILETYPE = 'ASC'
    WRITE_FIELD_SEPARATOR = 'X'
    WRITE_LF = 'X'
    tables
    data_tab = IG_ITAB .

    simple download from itab to file

    REPORT ZVENKATTEST0.

    data: begin of itab occurs 0,
    a type c,
    c type c,
    b type i,
    end of itab.

    itab-a = 'a' .
    itab-c = ':'.
    itab-b = 1 .
    append itab .


    itab-a = 'b' .
    itab-c = ':'.
    itab-b = 2 .
    append itab .


    itab-a = 'c' .
    itab-c = ':'.
    itab-b = 3 .
    append itab .

    data: file type string .

    file = 'C:\Documents and Settings\venkatapp\Desktop\test.txt'.


    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    FILENAME = file
    FILETYPE = 'ASC'
    WRITE_FIELD_SEPARATOR = ':'
    TABLES
    DATA_TAB = itab.

    upload or download

    REPORT ZTEST.

    DATA : G_FILE(128) TYPE C.
    DATA : G_PATH(80) TYPE C.
    DATA : G_END(8) TYPE C.
    DATA : G_SUBRC LIKE SY-SUBRC.

    PARAMETERS: P_UNAME LIKE SY-UNAME DEFAULT SY-UNAME.
    PARAMETERS: P_LANGU LIKE SY-LANGU DEFAULT SY-LANGU.

    SELECTION-SCREEN SKIP.

    PARAMETERS: P_IMP RADIOBUTTON GROUP ACT .
    PARAMETERS: P_EXP RADIOBUTTON GROUP ACT DEFAULT 'X'.

    SELECTION-SCREEN ULINE.
    SELECTION-SCREEN BEGIN OF BLOCK FIL.
    PARAMETERS: P_TYPE LIKE RLGRAP-FILETYPE DEFAULT 'ASC'.
    PARAMETERS: P_PATH LIKE G_PATH DEFAULT 'C:\TEMP\XXX.MEN'.

    SELECTION-SCREEN END OF BLOCK FIL.

    DATA: IT_USER_NODES TYPE TABLE OF BXMNODES1 WITH HEADER LINE.
    DATA: IT_FAV_NODES TYPE TABLE OF BXMNODES WITH HEADER LINE.

    DATA: BEGIN OF IT_PCF OCCURS 0,
    LINE(4096) TYPE C.
    DATA: END OF IT_PCF.

    INITIALIZATION.
    REPLACE 'XXX' WITH SY-UNAME INTO P_PATH.
    CONDENSE P_PATH NO-GAPS.
    SY-TITLE = 'UPLOAD/DOWNLOAD FAVORITE'.

    START-OF-SELECTION.

    CLEAR IT_USER_NODES[].
    CLEAR IT_FAV_NODES[].

    G_FILE = P_UNAME.

    IF P_UNAME <> SY-UNAME.
    MESSAGE W398(00) WITH 'CURRENT USER <> USER TO BE MODIFIED!'.
    ENDIF.

    IF P_IMP = 'X'.
    PERFORM IMPORT_FAV TABLES IT_FAV_NODES.
    PERFORM WRITE_FAV_DB TABLES IT_FAV_NODES.
    ELSEIF P_EXP = 'X'.
    PERFORM EXPORT_FAV TABLES IT_FAV_NODES.
    ENDIF.

    FORM DATA_EXPORT TABLES PIT_PCF
    USING P_FILE.
    CALL FUNCTION 'DOWNLOAD'
    EXPORTING
    FILENAME = P_FILE
    FILETYPE = P_TYPE
    TABLES
    DATA_TAB = PIT_PCF
    EXCEPTIONS
    FILE_OPEN_ERROR = 1
    FILE_WRITE_ERROR = 2
    INVALID_FILESIZE = 3
    INVALID_TABLE_WIDTH = 4
    INVALID_TYPE = 5
    NO_BATCH = 6
    UNKNOWN_ERROR = 7
    GUI_REFUSE_FILETRANSFER = 8
    OTHERS = 9.
    IF SY-SUBRC NE 0.
    WRITE: / 'FAILURE IN DOWNLOAD' , P_FILE.
    ENDIF.
    ENDFORM.

    FORM DATA_IMPORT TABLES PIT_PCF
    USING P_FILE P_SUBRC.
    CALL FUNCTION 'UPLOAD'
    EXPORTING
    FILENAME = P_FILE
    FILETYPE = P_TYPE
    TABLES
    DATA_TAB = PIT_PCF
    EXCEPTIONS
    CONVERSION_ERROR = 1
    FILE_OPEN_ERROR = 2
    FILE_READ_ERROR = 3
    INVALID_TABLE_WIDTH = 4
    INVALID_TYPE = 5
    NO_BATCH = 6
    UNKNOWN_ERROR = 7
    GUI_REFUSE_FILETRANSFER = 8
    OTHERS = 9.
    IF SY-SUBRC NE 0.
    WRITE: / 'UPLOAD FAILED' , P_FILE.
    P_SUBRC = SY-SUBRC .
    ENDIF.
    ENDFORM.

    FORM IMPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
    G_FILE = P_PATH.
    PERFORM DATA_IMPORT TABLES IT_FAV_NODES USING G_FILE G_SUBRC .
    ENDFORM.

    FORM EXPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
    CALL FUNCTION 'BX_FAVOS_READ_ALL_NODES'
    EXPORTING
    USER_NAME = P_UNAME
    LANGUAGE = P_LANGU
    TABLES
    OUTPUT_NODES_AND_TEXTS = IT_FAV_NODES.

    G_FILE = P_PATH.
    PERFORM DATA_EXPORT TABLES IT_FAV_NODES USING G_FILE .
    ENDFORM.

    FORM WRITE_FAV_DB TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
    CALL FUNCTION 'BX_FAVOS_WRITE_ALL_NODES'
    EXPORTING
    USER_NAME = P_UNAME
    TARGET_CLIENT = SY-MANDT
    TABLES
    INPUT_NODES_AND_TEXTS = PIT_FAV_NODES.

    ENDFORM.

    f4 help for month

    report ztest.
    tables: t247 , DFIES.

    parameters:p_month LIKE T247-MNR.

    data: begin of itab occurs 0,
    mnr like t247-mnr,
    ktx like t247-ktx,
    end of itab .

    DATA : LT_FIELDS TYPE TABLE OF DFIES,
    LS_FIELD TYPE DFIES.

    at selection-screen on value-request for p_month.

    select MNR
    KTX
    from t247 into corresponding fields of table itab
    where spras = 'EN'.

    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    RETFIELD = 'P_MONTH'
    DYNPPROG = sy-cprog
    DYNPNR = sy-dynnr
    DYNPROFIELD = 'MNR'
    VALUE_ORG = 'S'
    TABLES
    VALUE_TAB = itab
    FIELD_TAB = LT_FIELDS .

    f4 help for a field with ztable

    *--crete a z table with 2 fields and name(10) and age(2) and create entries..

    REPORT MESSAGE-ID ZMSF.

    TABLES:ZZZ000000 ,DFIES.

    DATA: BEGIN OF ITAB OCCURS 0,
    NAME(10) ,
    AGE(2),
    END OF ITAB.

    DATA : LT_FIELDS TYPE TABLE OF DFIES WITH HEADER LINE,
    LS_FIELD TYPE DFIES.

    PARAMETER: P_NAME(10) TYPE C.


    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_NAME.

    REFRESH ITAB.
    REFRESH LT_FIELDS.

    LT_FIELDS-TABNAME = 'ZZZ00000'.
    LT_FIELDS-FIELDNAME = 'NAME'.
    APPEND LT_FIELDS.
    CLEAR LT_FIELDS .

    LT_FIELDS-TABNAME = 'ZZZ00000'.
    LT_FIELDS-FIELDNAME = 'AGE'.
    LT_FIELDS-POSITION = '2'.

    APPEND LT_FIELDS.
    CLEAR LT_FIELDS .


    SELECT NAME
    AGE FROM ZZZ00000
    INTO TABLE ITAB.


    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    RETFIELD = LT_FIELDS-FIELDNAME
    DYNPPROG = SY-CPROG
    DYNPNR = SY-DYNNR
    DYNPROFIELD = 'NAME'
    VALUE_ORG = 'S'
    TABLES
    VALUE_TAB = ITAB
    FIELD_TAB = LT_FIELDS.

    f4 help for a z table

    *--create a z table with fields pernr like pa0002-pernr
    * vorna like pa0002-vorna
    * nachn like pa0002-nachn
    * and create entries for the table

    report message-id zmsf.

    tables:zzz000000 ,DFIES.

    DATA: BEGIN OF itab OCCURS 0,
    pernr like pa0002-pernr,
    vorna like pa0002-vorna,
    nachn like pa0002-nachn,
    END OF itab.

    DATA : LT_FIELDS TYPE TABLE OF DFIES,
    LS_FIELD TYPE DFIES.

    PARAMETER: pernr LIKE pa0002-pernr .


    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pernr.

    select pernr
    vorna
    nachn
    from zzz000000
    into table itab .

    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    RETFIELD = 'PERNR'
    DYNPPROG = sy-cprog
    DYNPNR = sy-dynnr
    DYNPROFIELD = 'PERNR'
    VALUE_ORG = 'S'
    TABLES
    VALUE_TAB = itab
    FIELD_TAB = LT_FIELDS .


    start-of-selection.

    select pernr
    vorna
    nachn
    from zzz000000
    into table itab
    where pernr = pernr.

    loop at itab.
    write:/ itab-pernr,
    itab-vorna,
    itab-nachn.
    endloop.

    f4 help for date

    report message-id zmsf.

    DATA:
    l_select_date LIKE workflds-gkday,
    l_select_week LIKE scal-week.

    * pop up calendar.
    CALL FUNCTION 'F4_DATE'
    EXPORTING
    date_for_first_month = sy-datum
    IMPORTING
    select_date = l_select_date
    select_week = l_select_week
    EXCEPTIONS
    calendar_buffer_not_loadable = 1
    date_after_range = 2
    date_before_range = 3
    date_invalid = 4
    factory_calendar_not_found = 5
    holiday_calendar_not_found = 6
    parameter_conflict = 7
    OTHERS = 8.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.


    * Validate date - An invalid date is caused by using the cancel
    * button on the calendar
    CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
    EXPORTING
    date = l_select_date
    EXCEPTIONS
    plausibility_check_failed = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    * User has cancelled the calendar
    EXIT.
    ENDIF.

    report header alignment

    report LINE-SIZE 200.

    WRITE:
    /(140) 'THIS IS THE HEADER OF THE PAGE' CENTERED,
    /(140) 'THIS IS THE VENKAT TEST HEADING' CENTERED,
    /(140) 'HI FRIEND THIS IS WORKING' CENTERED,

    /(10) 'date:' LEFT-JUSTIFIED,
    (10) sy-datum LEFT-JUSTIFIED,
    (90) 'CLIENT' RIGHT-JUSTIFIED,
    (08) SY-MANDT RIGHT-JUSTIFIED,
    /(10) 'time:' LEFT-JUSTIFIED,
    (10) sy-uzeit LEFT-JUSTIFIED,
    (92) 'USERNAME' RIGHT-JUSTIFIED,
    (10) SY-UNAME RIGHT-JUSTIFIED.

    inserting deleteing updating values from work area

    *--hi create a zdatabase table with 2 entries name(10) and age(2) .

    report ztest .

    tables:ZZZ00000.

    data: begin of itab occurs 0,
    name(10) type c,
    age type i,
    end of itab .
    selection-screen begin of line .
    parameters:p_wa(100) type c .
    selection-screen end of line .
    selection-screen skip 2.
    selection-screen begin of line .
    SELECTION-SCREEN:
    PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
    PUSHBUTTON 15(20) but2 USER-COMMAND cli2 ,
    PUSHBUTTON 40(20) but3 USER-COMMAND cli3 visible length 5 .

    selection-screen end of line .

    at selection-screen .

    case sy-ucomm .

    when 'CLI1'.
    ZZZ00000-name = p_wa+0(10) .
    ZZZ00000-age = p_wa+11(2).
    insert ZZZ00000.

    when 'CLI2'.
    delete from ZZZ00000 where name = p_wa+0(10)..

    when 'CLI3'.
    update ZZZ00000 from p_wa .

    endcase .

    alv blocked list

    REPORT z_alv_list_block.

    TYPE-POOLS: slis. " ALV Global types

    SELECTION-SCREEN :
    SKIP,
    BEGIN OF LINE,
    COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
    PARAMETERS p_max(2) TYPE n DEFAULT '02' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.

    DATA:
    * 1st Table
    BEGIN OF gt_kna1 OCCURS 0, " Data displayed
    kunnr LIKE kna1-kunnr, " Customer number
    ernam LIKE kna1-ernam, " Name of Person who Created
    erdat LIKE kna1-erdat, " Creation date
    name1 LIKE kna1-name1, " Name 1
    END OF gt_kna1,
    * 2nd Table
    BEGIN OF gt_mara OCCURS 0,
    ernam LIKE mara-ernam, " Name of Person who Created
    matnr LIKE mara-matnr, " Material number
    ersda LIKE mara-ersda, " Creation date
    brgew LIKE mara-brgew, " Gross weight
    END OF gt_mara,
    * 3rd Table
    BEGIN OF gt_vbak OCCURS 0,
    vkorg LIKE vbak-vkorg, " Sales organization
    kunnr LIKE vbak-kunnr, " Sold-to party
    vbeln LIKE vbak-vbeln, " Sales document
    netwr LIKE vbak-netwr, " Net Value of the Sales Order
    waerk LIKE vbak-waerk, " SD document currency
    END OF gt_vbak.


    INITIALIZATION.
    v_1 = 'Maximum of records to read'.


    START-OF-SELECTION.
    * Read data
    SELECT * FROM kna1
    UP TO p_max ROWS
    INTO CORRESPONDING FIELDS OF TABLE gt_kna1.

    SELECT * FROM mara
    UP TO p_max ROWS
    INTO CORRESPONDING FIELDS OF TABLE gt_mara.

    SELECT * FROM vbak
    UP TO p_max ROWS
    INTO CORRESPONDING FIELDS OF TABLE gt_vbak.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
    i_callback_program = sy-cprog
    i_callback_user_command = 'USER_COMMAND'.

    PERFORM list_append TABLES gt_kna1
    USING '1'
    'GT_KNA1'.

    PERFORM list_append TABLES gt_mara
    USING '2'
    'GT_MARA'.

    PERFORM list_append TABLES gt_vbak
    USING '3'
    'GT_VBAK'.

    PERFORM f_list_display.
    *---------------------------------------------------------------------*
    * FORM USER_COMMAND *
    *---------------------------------------------------------------------*
    FORM user_command USING i_ucomm LIKE sy-ucomm
    is_selfield TYPE slis_selfield. "#EC CALLED

    CASE i_ucomm.
    WHEN '&IC1'. " Pick
    CASE is_selfield-tabname.
    WHEN 'GT_MARA'.
    WHEN 'GT_KNA1'.
    WHEN 'GT_VBAK'.
    READ TABLE gt_vbak INDEX is_selfield-tabindex.

    IF sy-subrc EQ 0.
    * Sales order number
    SET PARAMETER ID 'AUN' FIELD gt_vbak-vbeln.

    * Display Sales Order
    CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    ENDIF.
    ENDCASE.
    ENDCASE.

    ENDFORM. " USER_COMMAND
    *---------------------------------------------------------------------*< /div>
    * Form list_append
    *---------------------------------------------------------------------*
    FORM list_append TABLES ut_table
    USING u_no TYPE char1
    u_tabname TYPE slis_tabname.
    * Macro definition
    DEFINE m_fieldcat.
    ls_fieldcat-fieldname = &1.
    ls_fieldcat-ref_tabname = &2.
    append ls_fieldcat to lt_fieldcat.
    END-OF-DEFINITION.
    DEFINE m_sort.
    ls_sort-fieldname = &1.
    ls_sort-up = 'X'.
    append ls_sort to lt_sort.
    END-OF-DEFINITION.
    DATA :
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
    ls_sort TYPE slis_sortinfo_alv,
    lt_sort TYPE slis_t_sortinfo_alv. " Sort table
    DATA:
    lt_events TYPE slis_t_event,
    ls_event TYPE slis_alv_event,
    ls_layout TYPE slis_layout_alv.
    ls_layout-group_change_edit = 'X'.
    ls_layout-colwidth_optimize = 'X'.
    ls_layout-zebra = 'X'.
    ls_layout-detail_popup = 'X'.
    ls_layout-get_selinfos = 'X'.
    ls_layout-max_linesize = '200'.

    CASE u_no.

    WHEN '1'.
    * Build field catalog and sort table
    m_fieldcat 'KUNNR' 'KNA1'.
    m_fieldcat 'ERNAM' 'KNA1'.
    m_fieldcat 'ERDAT' 'KNA1'.
    m_fieldcat 'NAME1' 'KNA1'.
    m_sort 'KUNNR'.

    WHEN '2'.
    m_fieldcat 'MATNR' 'MARA'.
    m_fieldcat 'ERNAM' 'MARA'.
    m_fieldcat 'ERSDA' 'MARA'.
    m_fieldcat 'BRGEW' 'MARA'.
    m_sort 'MATNR'.

    WHEN '3'.
    m_fieldcat 'VBELN' 'VBAK'.
    m_fieldcat 'VKORG' 'VBAK'.
    m_fieldcat 'KUNNR' 'VBAK'.
    m_fieldcat 'NETWR' 'VBAK'.
    m_fieldcat 'WAERK' 'VBAK'.
    m_sort 'VBELN'.

    ENDCASE.

    IF u_no CA '13'.
    MOVE 'TOP_OF_PAGE' TO ls_event-name.
    CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.
    APPEND ls_event TO lt_events.
    ELSE.
    MOVE 'TOP_OF_LIST' TO ls_event-name.
    CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.
    APPEND ls_event TO lt_events.
    ENDIF.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
    it_fieldcat = lt_fieldcat
    is_layout = ls_layout
    i_tabname = u_tabname
    it_events = lt_events
    it_sort = lt_sort
    TABLES
    t_outtab = ut_table .

    ENDFORM. " LIST_APPEND
    *---------------------------------------------------------------------*
    * Form f_list_display
    *---------------------------------------------------------------------*
    FORM f_list_display.

    DATA ls_print TYPE slis_print_alv.

    ls_print-no_print_selinfos = 'X'. " Display no selection infos
    ls_print-no_print_listinfos = 'X'. " Display no listinfos
    ls_print-reserve_lines = 2. " Lines reserved for end of page

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    EXPORTING
    i_interface_check = ' '
    is_print = ls_print .

    ENDFORM. " F_LIST_DISPLAY
    *---------------------------------------------------------------------*
    * FORM top_of_page1 *
    *---------------------------------------------------------------------*
    FORM top_of_page1. "#EC CALLED
    PERFORM top_of_page.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM top_of_page3 *
    *---------------------------------------------------------------------*
    FORM top_of_page3. "#EC CALLED
    PERFORM top_of_page.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM top_of_page *
    *---------------------------------------------------------------------*
    FORM top_of_page.
    ULINE.
    WRITE : sy-uname, sy-title(56) CENTERED, sy-datum.
    ULINE.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM top_of_list2 *
    *---------------------------------------------------------------------*
    FORM top_of_list2. "#EC CALLED
    WRITE 'TOP OF LIST2'.
    ENDFORM.

    alv interactive report with varient

    REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 650
    MESSAGE-ID ZZ_9838 .

    TYPE-POOLS: SLIS.
    *type declaration for values from ekko
    TYPES: BEGIN OF I_EKKO,
    EBELN LIKE EKKO-EBELN,
    AEDAT LIKE EKKO-AEDAT,
    BUKRS LIKE EKKO-BUKRS,
    BSART LIKE EKKO-BSART,
    LIFNR LIKE EKKO-LIFNR,
    END OF I_EKKO.

    DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,
    WA_EKKO TYPE I_EKKO.

    *type declaration for values from ekpo
    TYPES: BEGIN OF I_EKPO,
    EBELN LIKE EKPO-EBELN,
    EBELP LIKE EKPO-EBELP,
    MATNR LIKE EKPO-MATNR,
    MENGE LIKE EKPO-MENGE,
    MEINS LIKE EKPO-MEINS,
    NETPR LIKE EKPO-NETPR,
    END OF I_EKPO.

    DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,
    WA_EKPO TYPE I_EKPO .

    *variable for Report ID
    DATA: V_REPID LIKE SY-REPID .

    *declaration for fieldcatalog
    DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.


    DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.

    * declaration for events table where user comand or set PF status will
    * be defined
    DATA: V_EVENTS TYPE SLIS_T_EVENT,
    WA_EVENT TYPE SLIS_ALV_EVENT.

    * declartion for layout
    DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.

    * declaration for variant(type of display we want)
    DATA: I_VARIANT TYPE DISVARIANT,
    I_VARIANT1 TYPE DISVARIANT,
    I_SAVE(1) TYPE C.

    *PARAMETERS : p_var TYPE disvariant-variant.

    *Title displayed when the alv list is displayed
    DATA: I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
    DATA: I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.

    INITIALIZATION.
    V_REPID = SY-REPID.
    PERFORM BUILD_FIELDCATLOG.
    PERFORM EVENT_CALL.
    PERFORM POPULATE_EVENT.

    START-OF-SELECTION.
    PERFORM DATA_RETRIEVAL.
    PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
    PERFORM DISPLAY_ALV_REPORT.

    *&--------------------------------------------------------------------*
    *& Form BUILD_FIELDCATLOG
    *&--------------------------------------------------------------------*
    * Fieldcatalog has all the field details from ekko
    *---------------------------------------------------------------------*
    FORM BUILD_FIELDCATLOG.
    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
    WA_FIELDCAT-FIELDNAME = 'EBELN'.
    WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
    WA_FIELDCAT-FIELDNAME = 'AEDAT'.
    WA_FIELDCAT-SELTEXT_M = 'DATE.'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
    WA_FIELDCAT-FIELDNAME = 'BUKRS'.
    WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
    WA_FIELDCAT-FIELDNAME = 'BUKRS'.
    WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
    WA_FIELDCAT-FIELDNAME = 'LIFNR'.
    WA_FIELDCAT-NO_OUT = 'X'.
    WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.


    ENDFORM. "BUILD_FIELDCATLOG

    *&--------------------------------------------------------------------*
    *& Form EVENT_CALL
    *&--------------------------------------------------------------------*
    * we get all events - TOP OF PAGE or USER COMMAND in table v_events
    *---------------------------------------------------------------------*
    FORM EVENT_CALL.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    I_LIST_TYPE = 0
    IMPORTING
    ET_EVENTS = V_EVENTS .

    ENDFORM. "EVENT_CALL

    *&--------------------------------------------------------------------*
    *& Form POPULATE_EVENT
    *&--------------------------------------------------------------------*
    * Events populated for TOP OF PAGE & USER COMAND
    *---------------------------------------------------------------------*
    FORM POPULATE_EVENT.
    READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
    IF SY-SUBRC EQ 0.
    WA_EVENT-FORM = 'TOP_OF_PAGE'.
    MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
    ENDIF.

    READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
    IF SY-SUBRC EQ 0.
    WA_EVENT-FORM = 'USER_COMMAND'.
    MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-NAME.
    ENDIF.
    ENDFORM. "POPULATE_EVENT


    *&--------------------------------------------------------------------*
    *& Form data_retrieval
    *&--------------------------------------------------------------------*
    * retreiving values from the database table ekko
    *---------------------------------------------------------------------*
    FORM DATA_RETRIEVAL.
    SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.

    ENDFORM. "data_retrieval
    *&--------------------------------------------------------------------*
    *& Form bUild_listheader
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->I_LISTHEADEtext
    *---------------------------------------------------------------------*
    FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
    DATA HLINE TYPE SLIS_LISTHEADER.
    HLINE-INFO = 'this is my first alv pgm'.
    HLINE-TYP = 'H'.
    ENDFORM. "build_listheader

    *&--------------------------------------------------------------------*
    *& Form display_alv_report
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    FORM DISPLAY_ALV_REPORT.
    V_REPID = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = V_REPID
    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
    I_GRID_TITLE = I_TITLE_EKKO
    IT_FIELDCAT = I_FIELDCAT[]
    I_SAVE = 'A'
    IT_EVENTS = V_EVENTS
    TABLES
    T_OUTTAB = IT_EKKO .

    ENDFORM. "display_alv_report




    *&--------------------------------------------------------------------*
    *& Form TOP_OF_PAGE
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    FORM TOP_OF_PAGE.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = IT_LISTHEADER .

    ENDFORM. "TOP_OF_PAGE

    *&--------------------------------------------------------------------*
    *& Form USER_COMMAND
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->R_UCOMM text
    * -->, text
    * -->RS_SLEFIELDtext
    *---------------------------------------------------------------------*
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    CASE R_UCOMM.
    WHEN '&IC1'.
    READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
    PERFORM BUILD_FIELDCATLOG_EKPO.
    PERFORM EVENT_CALL_EKPO.
    PERFORM POPULATE_EVENT_EKPO.
    PERFORM DATA_RETRIEVAL_EKPO.
    PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
    PERFORM DISPLAY_ALV_EKPO.
    ENDCASE.
    ENDFORM. "user_command
    *&--------------------------------------------------------------------*
    *& Form BUILD_FIELDCATLOG_EKPO
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    FORM BUILD_FIELDCATLOG_EKPO.

    WA_FIELDCAT-TABNAME = 'IT_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'EBELN'.
    WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'IT_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'EBELP'.
    WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'I_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'MATNR'.
    WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'I_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'MENGE'.
    WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'I_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'MEINS'.
    WA_FIELDCAT-SELTEXT_M = 'UOM'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-TABNAME = 'I_EKPO'.
    WA_FIELDCAT-FIELDNAME = 'NETPR'.
    WA_FIELDCAT-SELTEXT_M = 'PRICE'.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.


    ENDFORM. "BUILD_FIELDCATLOG_EKPO

    *&--------------------------------------------------------------------*
    *& Form event_call_ekpo
    *&--------------------------------------------------------------------*
    * we get all events - TOP OF PAGE or USER COMMAND in table v_events
    *---------------------------------------------------------------------*
    FORM EVENT_CALL_EKPO.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    I_LIST_TYPE = 0
    IMPORTING
    ET_EVENTS = V_EVENTS .

    ENDFORM. "event_call_ekpo


    *&--------------------------------------------------------------------*
    *& Form POPULATE_EVENT
    *&--------------------------------------------------------------------*
    * Events populated for TOP OF PAGE & USER COMAND
    *---------------------------------------------------------------------*
    FORM POPULATE_EVENT_EKPO.
    READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
    IF SY-SUBRC EQ 0.
    WA_EVENT-FORM = 'TOP_OF_PAGE'.
    MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
    ENDIF.

    ENDFORM. "POPULATE_EVENT

    *&--------------------------------------------------------------------*
    *& Form TOP_OF_PAGE
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    FORM F_TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = IT_LISTHEADER .

    ENDFORM. "TOP_OF_PAGE

    *&--------------------------------------------------------------------*
    *& Form USER_COMMAND
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->R_UCOMM text
    * -->, text
    * -->RS_SLEFIELDtext
    *---------------------------------------------------------------------*

    *retreiving values from the database table ekko
    FORM DATA_RETRIEVAL_EKPO.
    SELECT EBELN EBELP MATNR MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO.
    ENDFORM.

    FORM BUILD_LISTHEADER_EKPO USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
    DATA: HLINE1 TYPE SLIS_LISTHEADER.
    HLINE1-TYP = 'H'.
    HLINE1-INFO = 'CHECKING PGM'.
    ENDFORM.


    FORM DISPLAY_ALV_EKPO.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = V_REPID
    I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
    I_GRID_TITLE = I_TITLE_EKPO
    IT_FIELDCAT = I_FIELDCAT[]
    I_SAVE = 'A'
    IT_EVENTS = V_EVENTS
    TABLES
    T_OUTTAB = IT_EKPO .
    ENDFORM.

    alv grid display report

    REPORT ZTUFI091 .
    *&---------------------------------------------------------------------*
    *& Report ZDEMO_ALVGRID *
    *& *
    *&---------------------------------------------------------------------*
    *& *
    *& Example of a simple ALV Grid Report *
    *& ................................... *
    *& *
    *& The basic requirement for this demo is to display a number of *
    *& fields from the EKKO table. *
    *&---------------------------------------------------------------------*
    *REPORT zdemo_alvgrid .

    TABLES: ekko.

    type-pools: slis. "ALV Declarations
    *Data Declaration
    *----------------
    TYPES: BEGIN OF t_ekko,
    ebeln TYPE ekpo-ebeln,
    ebelp TYPE ekpo-ebelp,
    statu TYPE ekpo-statu,
    aedat TYPE ekpo-aedat,
    matnr TYPE ekpo-matnr,
    menge TYPE ekpo-menge,
    meins TYPE ekpo-meins,
    netpr TYPE ekpo-netpr,
    peinh TYPE ekpo-peinh,
    END OF t_ekko.

    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
    wa_ekko TYPE t_ekko.

    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
    gd_tab_group type slis_t_sp_group_alv,
    gd_layout type slis_layout_alv,
    gd_repid like sy-repid,
    gt_events type slis_t_event,
    gd_prntparams type slis_print_alv.


    ************************************************************************
    *Start-of-selection.
    START-OF-SELECTION.

    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform build_events.
    perform build_print_params.
    perform display_alv_report.


    *&---------------------------------------------------------------------*
    *& Form BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    * Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    form build_fieldcatalog.

    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you more control of the final product.

    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    * I.e. Field type may be required in-order for
    * the 'TOTAL' function to work.

    fieldcatalog-fieldname = 'EBELN'.
    fieldcatalog-seltext_m = 'Purchase Order'.
    fieldcatalog-col_pos = 0.
    fieldcatalog-outputlen = 10.
    fieldcatalog-emphasize = 'X'.
    fieldcatalog-key = 'X'.
    * fieldcatalog-do_sum = 'X'.
    * fieldcatalog-no_zero = 'X'.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'EBELP'.
    fieldcatalog-seltext_m = 'PO Item'.
    fieldcatalog-col_pos = 1.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'STATU'.
    fieldcatalog-seltext_m = 'Status'.
    fieldcatalog-col_pos = 2.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'AEDAT'.
    fieldcatalog-seltext_m = 'Item change date'.
    fieldcatalog-col_pos = 3.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MATNR'.
    fieldcatalog-seltext_m = 'Material Number'.
    fieldcatalog-col_pos = 4.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MENGE'.
    fieldcatalog-seltext_m = 'PO quantity'.
    fieldcatalog-col_pos = 5.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'MEINS'.
    fieldcatalog-seltext_m = 'Order Unit'.
    fieldcatalog-col_pos = 6.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'NETPR'.
    fieldcatalog-seltext_m = 'Net Price'.
    fieldcatalog-col_pos = 7.
    fieldcatalog-outputlen = 15.
    fieldcatalog-datatype = 'CURR'.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.

    fieldcatalog-fieldname = 'PEINH'.
    fieldcatalog-seltext_m = 'Price Unit'.
    fieldcatalog-col_pos = 8.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.
    endform. " BUILD_FIELDCATALOG


    *&---------------------------------------------------------------------*
    *& Form BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    * Build layout for ALV grid report
    *----------------------------------------------------------------------*
    form build_layout.
    gd_layout-no_input = 'X'.
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-totals_text = 'Totals'(201).
    * gd_layout-totals_only = 'X'.
    * gd_layout-f2code = 'DISP'. "Sets fcode for when double
    * "click(press f2)
    * gd_layout-zebra = 'X'.
    * gd_layout-group_change_edit = 'X'.
    * gd_layout-header_text = 'helllllo'.
    endform. " BUILD_LAYOUT


    *&---------------------------------------------------------------------*
    *& Form DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    * Display report using ALV grid
    *----------------------------------------------------------------------*
    form display_alv_report.
    gd_repid = sy-repid.
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    i_callback_program = gd_repid
    i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
    i_callback_user_command = 'USER_COMMAND'
    * i_grid_title = outtext
    is_layout = gd_layout
    it_fieldcat = fieldcatalog[]
    * it_special_groups = gd_tabgroup
    it_events = gt_events
    is_print = gd_prntparams
    i_save = 'X'
    * is_variant = z_template
    tables
    t_outtab = it_ekko
    exceptions
    program_error = 1
    others = 2.
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    endform. " DISPLAY_ALV_REPORT


    *&---------------------------------------------------------------------*
    *& Form DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    * Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    form data_retrieval.

    select ebeln ebelp statu aedat matnr menge meins netpr peinh
    up to 10 rows
    from ekpo
    into table it_ekko.
    endform. " DATA_RETRIEVAL


    *-------------------------------------------------------------------*
    * Form TOP-OF-PAGE *
    *-------------------------------------------------------------------*
    * ALV Report Header *
    *-------------------------------------------------------------------*
    Form top-of-page.
    *ALV Header declarations
    data: t_header type slis_t_listheader,
    wa_header type slis_listheader,
    t_line like wa_header-info,
    ld_lines type i,
    ld_linesc(10) type c.

    * Title
    wa_header-typ = 'H'.
    wa_header-info = 'EKKO Table Report'.
    append wa_header to t_header.
    clear wa_header.

    * Date
    wa_header-typ = 'S'.
    wa_header-key = 'Date: '.
    CONCATENATE sy-datum+6(2) '.'
    sy-datum+4(2) '.'
    sy-datum(4) INTO wa_header-info. "todays date
    append wa_header to t_header.
    clear: wa_header.

    * Total No. of Records Selected
    describe table it_ekko lines ld_lines.
    ld_linesc = ld_lines.
    concatenate 'Total No. of Records Selected: ' ld_linesc
    into t_line separated by space.
    wa_header-typ = 'A'.
    wa_header-info = t_line.
    append wa_header to t_header.
    clear: wa_header, t_line.

    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = t_header.
    * i_logo = 'Z_LOGO'.
    endform.


    *------------------------------------------------------------------*
    * FORM USER_COMMAND *
    *------------------------------------------------------------------*
    * --> R_UCOMM *
    * --> RS_SELFIELD *
    *------------------------------------------------------------------*
    FORM user_command USING r_ucomm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield.

    * Check function code
    CASE r_ucomm.
    WHEN '&IC1'.
    * Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
    * Read data table, using index of row user clicked on
    READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    * Set parameter ID for transaction screen field
    SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    * Sxecute transaction ME23N, and skip initial data entry screen
    CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
    ENDCASE.
    ENDFORM.


    *&---------------------------------------------------------------------*
    *& Form BUILD_EVENTS
    *&---------------------------------------------------------------------*
    * Build events table
    *----------------------------------------------------------------------*
    form build_events.
    data: ls_event type slis_alv_event.

    call function 'REUSE_ALV_EVENTS_GET'
    exporting
    i_list_type = 0
    importing
    et_events = gt_events[].
    read table gt_events with key name = slis_ev_end_of_page
    into ls_event.
    if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
    endif.

    read table gt_events with key name = slis_ev_end_of_list
    into ls_event.
    if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
    endif.
    endform. " BUILD_EVENTS


    *&---------------------------------------------------------------------*
    *& Form BUILD_PRINT_PARAMS
    *&---------------------------------------------------------------------*
    * Setup print parameters
    *----------------------------------------------------------------------*
    form build_print_params.
    gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
    gd_prntparams-no_coverpage = 'X'.
    endform. " BUILD_PRINT_PARAMS


    *&---------------------------------------------------------------------*
    *& Form END_OF_PAGE
    *&---------------------------------------------------------------------*
    form END_OF_PAGE.
    data: listwidth type i,
    ld_pagepos(10) type c,
    ld_page(10) type c.

    write: sy-uline(50).
    skip.
    write:/40 'Page:', sy-pagno .
    endform.


    *&---------------------------------------------------------------------*
    *& Form END_OF_LIST
    *&---------------------------------------------------------------------*
    form END_OF_LIST.
    data: listwidth type i,
    ld_pagepos(10) type c,
    ld_page(10) type c.

    skip.
    write:/40 'Page:', sy-pagno .
    endform.

    icons in alv

    *&---------------------------------------------------------------------*
    *& Report ZALV_ICON *
    *& *
    *&---------------------------------------------------------------------*

    REPORT ZALV_ICON .
    ************************************************************************
    * Include Programs
    ************************************************************************
    INCLUDE .

    ************************************************************************
    * Database Tables
    ************************************************************************
    TABLES: kna1. "Customer Master

    ************************************************************************
    * Types
    ************************************************************************
    TYPE-POOLS: kkblo.

    ************************************************************************
    * Structures
    ************************************************************************
    * Structure to hold the Color Information
    DATA: BEGIN OF st_color,
    color(3) TYPE c,
    END OF st_color.

    * Structure to hold the Icon Information
    DATA: BEGIN OF st_icon,
    icon(4) TYPE c,
    END OF st_icon.

    * ALV Field Catalog Structure
    DATA: st_fieldcat TYPE slis_fieldcat_alv.

    * ALV Layout Structure
    DATA: st_layout TYPE slis_layout_alv.

    ************************************************************************
    * Internal Tables
    ************************************************************************
    * Output Table
    DATA: BEGIN OF tbl_kna1 OCCURS 0.
    INCLUDE STRUCTURE st_icon. "Icon Structure
    INCLUDE STRUCTURE kna1. "Customer Master Structure
    INCLUDE STRUCTURE st_color. "Color Structure
    DATA: END OF tbl_kna1.

    * ALV Field Catalog Table
    DATA: tbl_fieldcat TYPE slis_t_fieldcat_alv.

    ************************************************************************
    * Variables
    ************************************************************************
    DATA: fieldname(30) TYPE c,
    g_repid LIKE sy-repid.

    ************************************************************************
    * Start of Selection
    ************************************************************************
    START-OF-SELECTION.

    g_repid = sy-repid.

    PERFORM get_data.

    ************************************************************************
    * End of Selection
    ************************************************************************
    END-OF-SELECTION.

    PERFORM do_fancy_stuff.
    PERFORM get_layout.
    PERFORM get_fieldcat.
    PERFORM create_report.


    *&---------------------------------------------------------------------*
    *& Form CREATE_REPORT
    *&---------------------------------------------------------------------*
    * Learn to read the subroutine name!
    *----------------------------------------------------------------------*
    FORM create_report.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_interface_check = ' '
    i_callback_program = g_repid
    i_callback_user_command = 'PROCESS_USER_COMMANDS'
    it_fieldcat = tbl_fieldcat
    i_default = 'X'
    i_save = ' '
    is_layout = st_layout
    TABLES
    t_outtab = tbl_kna1
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    ENDFORM. " CREATE_REPORT

    *&---------------------------------------------------------------------*
    *& Form GET_FIELDCAT
    *&---------------------------------------------------------------------*
    * Build the Field Catalog
    *----------------------------------------------------------------------*
    FORM get_fieldcat.
    * Here the field catalog is created. To display more fields simply
    * 'uncomment' the additional lines and add the field name. Also note
    * that the field catalog is much more powerful than this. You can
    * intensify fields, change the colour, assign reference fields, etc.
    * Look at type slis_fieldcat_alv for more options.
    PERFORM write_fieldcat USING 'ICON' 'TBL_KNA1' ' ' 'X' 1 '2' 'X'
    ' '.
    PERFORM write_fieldcat USING 'KUNNR' 'TBL_KNA1' 'KNA1' 'X' 2 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'NAME1' 'TBL_KNA1' 'KNA1' ' ' 3 '10' ' '
    'X'.
    PERFORM write_fieldcat USING 'STRAS' 'TBL_KNA1' 'KNA1' ' ' 4 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'TELF1' 'TBL_KNA1' 'KNA1' ' ' 5 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'ORT01' 'TBL_KNA1' 'KNA1' ' ' 6 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'PSTLZ' 'TBL_KNA1' 'KNA1' ' ' 7 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'SORTL' 'TBL_KNA1' 'KNA1' ' ' 8 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'ERNAM' 'TBL_KNA1' 'KNA1' ' ' 9 ' ' ' '
    ' '.
    PERFORM write_fieldcat USING 'SPRAS' 'TBL_KNA1' 'KNA1' ' ' 10 ' ' ' '
    ' '.
    * perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 10 ' '.
    * perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 11 ' '.
    * perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 12 ' '.

    ENDFORM. " GET_FIELDCAT

    *&---------------------------------------------------------------------*
    *& Form WRITE_FIELDCAT
    *&---------------------------------------------------------------------*
    * Write the Field Catalog data to the Field Catalog Table
    *----------------------------------------------------------------------*
    * -->name Field name
    * -->tab Table name
    * -->st Structure Name
    * -->key Is this field a Key?
    * -->pos Position Number
    * -->length Field Length
    * -->icon Display as Icon
    * -->hot Hotspot
    *----------------------------------------------------------------------*
    FORM write_fieldcat USING name tab st key pos length icon hot.

    st_fieldcat-fieldname = name.
    st_fieldcat-tabname = tab.
    st_fieldcat-ref_tabname = st.
    st_fieldcat-key = key.
    st_fieldcat-col_pos = pos.
    st_fieldcat-outputlen = length.
    st_fieldcat-icon = icon.
    st_fieldcat-hotspot = hot.
    APPEND st_fieldcat TO tbl_fieldcat.
    CLEAR st_fieldcat.

    ENDFORM. " WRITE_FIELDCAT

    *&---------------------------------------------------------------------*
    *& Form PROCESS_USER_COMMANDS
    *&---------------------------------------------------------------------*
    * Interactive Reporting Commands
    *----------------------------------------------------------------------*
    FORM process_user_commands USING syst-ucomm LIKE syst-ucomm
    selfield TYPE slis_selfield.

    * This subroutine is called when there is user interaction in the output
    * In this case if the user double clicks the Customer Number then the
    * program will call transaction XD03 and display the Customer Master
    * Data

    CASE syst-ucomm.
    WHEN '&IC1'.
    * get cursor field fieldname.
    READ TABLE tbl_kna1 INDEX selfield-tabindex.
    SET PARAMETER ID 'KUN' FIELD tbl_kna1-kunnr.
    CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
    ENDCASE.

    ENDFORM. " PROCESS_USER_COMMANDS

    *&---------------------------------------------------------------------*
    *& Form GET_LAYOUT
    *&---------------------------------------------------------------------*
    * set the layout of the ALV.
    * add color to the row?
    *----------------------------------------------------------------------*
    FORM get_layout.

    st_layout-info_fieldname = 'COLOR'.
    st_layout-colwidth_optimize = 'X'.
    st_layout-get_selinfos = 'X'.

    ENDFORM. " GET_LAYOUT
    *&---------------------------------------------------------------------*
    *& Form get_data
    *&---------------------------------------------------------------------*
    * Get some data to play with
    *----------------------------------------------------------------------*
    FORM get_data.

    SELECT * FROM kna1 INTO CORRESPONDING FIELDS OF TABLE tbl_kna1
    UP TO 30 ROWS.

    ENDFORM. " get_data
    *&---------------------------------------------------------------------*
    *& Form do_fancy_stuff
    *&---------------------------------------------------------------------*
    * Do some fancy pants stuff for example changing the color of
    * lines and adding icons
    *----------------------------------------------------------------------*
    FORM do_fancy_stuff.

    * Here we will demonstrate changing the color of ALV Record lines as
    * well as displaying Icons
    LOOP AT tbl_kna1.
    * All records where NAME1 begins with 'M', will be displayed in Bluish
    * Green
    IF tbl_kna1-name1(1) EQ 'M'.
    tbl_kna1-color = 'C41'. "Bluish Green
    MODIFY tbl_kna1 TRANSPORTING color.
    ENDIF.

    * All records with no TELF1 will be displayed in White and have a
    * Warning Icon
    IF tbl_kna1-telf1 IS INITIAL.
    tbl_kna1-color = 'C00'. "White
    tbl_kna1-icon = '@AH@'. "Warning Icon
    MODIFY tbl_kna1 TRANSPORTING icon color.
    ENDIF.
    ENDLOOP.

    ENDFORM. " do_fancy_stuff

    get fields of any table

    REPORT YTABFLDS .
    TABLES: DD02L, DD03L, DD04T.

    PARAMETERS THETABLE LIKE DD02L-TABNAME OBLIGATORY.
    DATA: BEGIN OF MYTABLE,
    TABNAME LIKE DD02L-TABNAME,
    AS4LOCAL LIKE DD02L-AS4LOCAL,
    AS4VERS LIKE DD02L-AS4VERS,
    END OF MYTABLE.

    SELECT SINGLE TABNAME AS4LOCAL AS4VERS INTO MYTABLE FROM DD03L
    WHERE TABNAME = THETABLE.
    WRITE: / MYTABLE-TABNAME, 11 MYTABLE-AS4LOCAL, 13 MYTABLE-AS4VERS.
    SELECT * FROM DD03L
    WHERE TABNAME = MYTABLE-TABNAME AND
    AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS.
    WRITE: / DD03L-FIELDNAME, 11 DD03L-KEYFLAG, 13 DD03L-ROLLNAME,
    24 DD03L-CHECKTABLE, 35 DD03L-INTTYPE, 37 DD03L-REFTABLE,
    48 DD03L-DATATYPE.
    SELECT SINGLE * FROM DD04T
    WHERE ROLLNAME = DD03L-ROLLNAME AND
    AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS AND
    DDLANGUAGE = 'E'.

    WRITE: 53 DD04T-DDTEXT.
    ENDSELECT.

    different select statements

    For all entries

    The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of
    entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the
    length of the WHERE clause.
    The plus

    Large amount of data
    Mixing processing and reading of data
    Fast internal reprocessing of data
    Fast
    The Minus
    Difficult to program/understand
    Memory could be critical (use FREE or PACKAGE size)
    Some steps that might make FOR ALL ENTRIES more efficient:
    Removing duplicates from the the driver table
    Sorting the driver table
    If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
    FOR ALL ENTRIES IN i_tab
    WHERE mykey >= i_tab-low and
    mykey <= i_tab-high.
    Nested selects

    The plus:
    Small amount of data
    Mixing processing and reading of data
    Easy to code - and understand
    The minus:
    Large amount of data
    when mixed processing isn’t needed
    Performance killer no. 1

    Select using JOINS

    The plus
    Very large amount of data
    Similar to Nested selects - when the accesses are planned by the programmer
    In some cases the fastest
    Not so memory critical
    The minus
    Very difficult to program/understand
    Mixing processing and reading of data not possible

    Use the selection criteria

    SELECT * FROM SBOOK.
    CHECK: SBOOK-CARRID = 'LH' AND
    SBOOK-CONNID = '0400'.
    ENDSELECT.
    SELECT * FROM SBOOK
    WHERE CARRID = 'LH' AND
    CONNID = '0400'.
    ENDSELECT.

    Use the aggregated functions

    C4A = '000'.
    SELECT * FROM T100
    WHERE SPRSL = 'D' AND
    ARBGB = '00'.
    CHECK: T100-MSGNR > C4A.
    C4A = T100-MSGNR.
    ENDSELECT.

    SELECT MAX( MSGNR ) FROM T100 INTO C4A
    WHERE SPRSL = 'D' AND
    ARBGB = '00'.

    Select with view

    SELECT * FROM DD01L
    WHERE DOMNAME LIKE 'CHAR%'
    AND AS4LOCAL = 'A'.
    SELECT SINGLE * FROM DD01T
    WHERE DOMNAME = DD01L-DOMNAME
    AND AS4LOCAL = 'A'
    AND AS4VERS = DD01L-AS4VERS
    AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.

    SELECT * FROM DD01V
    WHERE DOMNAME LIKE 'CHAR%'
    AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.

    Select with index support

    SELECT * FROM T100
    WHERE ARBGB = '00'
    AND MSGNR = '999'.
    ENDSELECT.

    SELECT * FROM T002.
    SELECT * FROM T100
    WHERE SPRSL = T002-SPRAS
    AND ARBGB = '00'
    AND MSGNR = '999'.
    ENDSELECT.
    ENDSELECT.


    Select … Into table

    REFRESH X006.
    SELECT * FROM T006 INTO X006.
    APPEND X006.
    ENDSELECT

    SELECT * FROM T006 INTO TABLE X006.


    Select with selection list

    SELECT * FROM DD01L
    WHERE DOMNAME LIKE 'CHAR%'
    AND AS4LOCAL = 'A'.
    ENDSELECT

    SELECT DOMNAME FROM DD01L
    INTO DD01L-DOMNAME
    WHERE DOMNAME LIKE 'CHAR%'
    AND AS4LOCAL = 'A'.
    ENDSELECT

    Key access to multiple lines

    LOOP AT TAB.
    CHECK TAB-K = KVAL.
    " ...
    ENDLOOP.

    LOOP AT TAB WHERE K = KVAL.
    " ...
    ENDLOOP.


    Copying internal tables

    REFRESH TAB_DEST.
    LOOP AT TAB_SRC INTO TAB_DEST.
    APPEND TAB_DEST.
    ENDLOOP.

    TAB_DEST[] = TAB_SRC[].

    Modifying a set of lines

    LOOP AT TAB.
    IF TAB-FLAG IS INITIAL.
    TAB-FLAG = 'X'.
    ENDIF.
    MODIFY TAB.
    ENDLOOP.

    TAB-FLAG = 'X'.
    MODIFY TAB TRANSPORTING FLAG
    WHERE FLAG IS INITIAL.

    Deleting a sequence of lines

    DO 101 TIMES.
    DELETE TAB_DEST INDEX 450.
    ENDDO.

    DELETE TAB_DEST FROM 450 TO 550.


    Linear search vs. binary

    READ TABLE TAB WITH KEY K = 'X'.

    READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
    Comparison of internal tables
    DESCRIBE TABLE: TAB1 LINES L1,
    TAB2 LINES L2.

    IF L1 <> L2.
    TAB_DIFFERENT = 'X'.
    ELSE.
    TAB_DIFFERENT = SPACE.
    LOOP AT TAB1.
    READ TABLE TAB2 INDEX SY-TABIX.
    IF TAB1 <> TAB2.
    TAB_DIFFERENT = 'X'. EXIT.
    ENDIF.
    ENDLOOP.
    ENDIF.

    IF TAB_DIFFERENT = SPACE.
    " ...
    ENDIF.

    IF TAB1[] = TAB2[].
    " ...
    ENDIF.

    Modify selected components

    LOOP AT TAB.
    TAB-DATE = SY-DATUM.
    MODIFY TAB.
    ENDLOOP.

    WA-DATE = SY-DATUM.
    LOOP AT TAB.
    MODIFY TAB FROM WA TRANSPORTING DATE.
    ENDLOOP.

    Appending two internal tables

    LOOP AT TAB_SRC.
    APPEND TAB_SRC TO TAB_DEST.
    ENDLOOP

    APPEND LINES OF TAB_SRC TO TAB_DEST.

    Deleting a set of lines

    LOOP AT TAB_DEST WHERE K = KVAL.
    DELETE TAB_DEST.
    ENDLOOP

    DELETE TAB_DEST WHERE K = KVAL.


    Tools available in SAP to pin-point a performance problem

    The runtime analysis (SE30)
    SQL Trace (ST05)
    Tips and Tricks tool
    The performance database

    Optimizing the load of the database

    Using table buffering
    Using buffered tables improves the performance considerably. Note that in some cases a stament can not be used with a buffered table, so when using these staments the buffer will be bypassed. These staments are:
    Select DISTINCT
    ORDER BY / GROUP BY / HAVING clause
    Any WHERE clasuse that contains a subquery or IS NULL expression
    JOIN s
    A SELECT... FOR UPDATE
    If you wnat to explicitly bypass the bufer, use the BYPASS BUFFER addition to the SELECT clause.
    Use the ABAP SORT Clause Instead of ORDER BY
    The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The datbase server will usually be the bottleneck, so sometimes it is better to move thje sort from the datsbase server to the application server.
    If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT stament to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the datbase server sort it.

    Avoid ther SELECT DISTINCT Statement

    As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplciate rows.

    left outerjoin

    report ztest.
    DATA: CUSTOMER TYPE SCUSTOM,
    BOOKING TYPE SBOOK.

    SELECT SCUSTOM~NAME
    SCUSTOM~POSTCODE
    SCUSTOM~CITY
    SBOOK~FLDATE
    SBOOK~CARRID
    SBOOK~CONNID
    SBOOK~BOOKID
    INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID)
    FROM SCUSTOM LEFT OUTER JOIN SBOOK
    ON SCUSTOM~ID = SBOOK~CUSTOMID AND
    SBOOK~FLDATE = '20081015'
    ORDER BY SCUSTOM~NAME SBOOK~FLDATE.
    WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID.
    ENDSELECT.

    give name of function module get details of that

    PROGRAM yclip3jnc.

    TYPE-POOLS : slis.

    PARAMETERS: p_func LIKE fupararef-funcname. " Name of Function Module

    DATA : BEGIN OF i_tab OCCURS 0,
    funcname LIKE fupararef-funcname, " Name of Function Module
    paramtype LIKE fupararef-paramtype, " Parameter type
    pposition LIKE fupararef-pposition, " Internal Table, Current Line Index
    optional LIKE fupararef-optional, " Optional parameters
    parameter LIKE fupararef-parameter, " Parameter name
    defaultval LIKE fupararef-defaultval, " Default value for import parameter
    structure LIKE fupararef-structure, " Associated Type of an Interface Parameter
    stext LIKE funct-stext, " Short text
    END OF i_tab.

    DATA: BEGIN OF mtab_new_prog OCCURS 0,
    line(172) TYPE c,
    END OF mtab_new_prog.

    DATA: funcdesc LIKE tftit-stext, " Short text for function module
    mylen TYPE i,
    myrc TYPE i.

    CONSTANTS: myhats(40) VALUE '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'.

    TRANSLATE p_func TO UPPER CASE.

    SELECT SINGLE
    tftit~stext " Short text for function module
    INTO funcdesc
    FROM tftit
    WHERE tftit~funcname = p_func
    AND tftit~spras = sy-langu.

    TRANSLATE p_func TO LOWER CASE.

    CONCATENATE `CALL FUNCTION ` p_func ` " ` funcdesc INTO mtab_new_prog-line.
    APPEND mtab_new_prog.

    TRANSLATE p_func TO UPPER CASE.

    SELECT
    fupararef~funcname " Name of Function Module
    fupararef~paramtype " Parameter type
    fupararef~pposition " Internal Table, Current Line Index
    fupararef~optional " Optional parameters
    fupararef~parameter " Parameter name
    fupararef~defaultval " Default value for import parameter
    fupararef~structure " Associated Type of an Interface Parameter
    funct~stext " Short text
    INTO TABLE i_tab
    FROM fupararef
    INNER JOIN funct
    ON fupararef~funcname = funct~funcname
    AND fupararef~parameter = funct~parameter
    AND funct~spras = sy-langu
    WHERE fupararef~funcname = p_func
    AND fupararef~r3state = 'A'
    ORDER BY fupararef~paramtype
    fupararef~pposition.


    LOOP AT i_tab.
    AT NEW paramtype.
    CASE i_tab-paramtype.
    WHEN 'C'.
    MOVE ' CHANGING' TO mtab_new_prog-line.
    WHEN 'E'.
    MOVE ' IMPORTING' TO mtab_new_prog-line.
    WHEN 'I'.
    MOVE ' EXPORTING' TO mtab_new_prog-line.
    WHEN 'T'.
    MOVE ' TABLES' TO mtab_new_prog-line.
    WHEN 'X'.
    MOVE ' EXCEPTIONS' TO mtab_new_prog-line.
    ENDCASE.
    APPEND mtab_new_prog.
    ENDAT.

    IF i_tab-optional = 'X'.
    mtab_new_prog-line = `*^^^`.
    ELSE.
    mtab_new_prog-line = `^^^^`.
    ENDIF.

    IF i_tab-paramtype = 'X'.
    MOVE i_tab-pposition TO i_tab-defaultval.
    CONDENSE i_tab-defaultval.
    ELSE.
    TRANSLATE i_tab-parameter TO LOWER CASE.
    ENDIF.

    CONCATENATE mtab_new_prog-line i_tab-parameter '^=^' INTO mtab_new_prog-line.

    IF i_tab-defaultval IS NOT INITIAL.
    CONCATENATE mtab_new_prog-line i_tab-defaultval INTO mtab_new_prog-line.
    ENDIF.

    mylen = STRLEN( mtab_new_prog-line ).

    IF mylen < 31.
    COMPUTE mylen = 31 - mylen.
    ELSE.
    MOVE 1 TO mylen.
    ENDIF.

    TRANSLATE i_tab-structure TO LOWER CASE.

    CONCATENATE mtab_new_prog-line myhats+0(mylen) ` " ` i_tab-structure INTO mtab_new_prog-line.

    mylen = STRLEN( mtab_new_prog-line ).

    IF mylen < 47.
    COMPUTE mylen = 47 - mylen.
    ELSE.
    MOVE 1 TO mylen.
    ENDIF.

    CONCATENATE mtab_new_prog-line myhats+0(mylen) ` ` i_tab-stext INTO mtab_new_prog-line.

    APPEND mtab_new_prog.
    ENDLOOP. " LOOP AT I_TAB

    CONCATENATE ` . " ` p_func INTO mtab_new_prog-line.
    APPEND mtab_new_prog.

    LOOP AT mtab_new_prog.
    TRANSLATE mtab_new_prog-line USING `^ `.
    MODIFY mtab_new_prog.

    IF mtab_new_prog = space.
    SKIP 1.
    ENDIF.
    WRITE: / mtab_new_prog.
    ENDLOOP. " LOOP AT MTAB_NEW_PROG

    * Write the beautiful program code to ClipBoard from internal table
    CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
    data = mtab_new_prog[]
    CHANGING
    rc = myrc.

    abap clip board

    REPORT yclipjnc. .

    TABLES:
    e071 , " Change & Transport System: Object Entries of Requests/Tasks
    tadir , " Directory of Repository Objects
    trdir , " Generated Table for View TRDIR
    dd02t . " R/3 DD: SAP table texts

    DATA: BEGIN OF mtab_old_prog OCCURS 0,
    line(172) TYPE c,
    END OF mtab_old_prog.

    DATA: BEGIN OF mtab_new_prog OCCURS 0,
    line(172) TYPE c,
    END OF mtab_new_prog.

    DATA: BEGIN OF mtab_jnc_prog OCCURS 0,
    line(172) TYPE c,
    END OF mtab_jnc_prog.

    DATA:
    * Hold an entire statement, even if it spans multiple lines
    BEGIN OF mtab_long_line OCCURS 0,
    start TYPE i,
    end TYPE i,
    code(9999) TYPE c, "For type "C", a maximum length specification of 65535 is allowed.
    END OF mtab_long_line.

    DATA: BEGIN OF mtab_tabname OCCURS 0,
    tabname LIKE dd02t-tabname, " Table name
    tabdesc LIKE dd02t-ddtext, " Short text describing ABAP/4
    *Dictio
    END OF mtab_tabname.

    * Queue to hold list of internal table names for commenting the ENDLOOP
    * line
    DATA: BEGIN OF mtab_itab_names OCCURS 0,
    tabname(40) TYPE c,
    END OF mtab_itab_names.

    * Queue to hold list of table names for commenting the ENDSELECT line
    DATA: BEGIN OF mtab_tab_names OCCURS 0,
    tabname(40) TYPE c,
    END OF mtab_tab_names.

    DATA: BEGIN OF mtab_form_names OCCURS 0,
    tabname(40) TYPE c,
    END OF mtab_form_names.

    DATA: mylength TYPE i,
    myrc TYPE i.

    CONSTANTS: myhats(40) VALUE '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'.

    * START of EXECUTION

    * Read the program code in ClipBoard into an internal table
    CALL METHOD cl_gui_frontend_services=>clipboard_import
    IMPORTING
    data = mtab_old_prog[]
    length = mylength.

    IF sy-subrc NE 0.
    WRITE: / `Unable to read ClipBoard`.
    WRITE: / `Exiting program`.
    ENDIF.

    PERFORM create_condensed_table TABLES mtab_old_prog mtab_long_line.

    PERFORM format_program.

    CALL FUNCTION `PRETTY_PRINTER`
    EXPORTING
    inctoo = space
    TABLES
    ntext = mtab_jnc_prog
    otext = mtab_new_prog
    EXCEPTIONS
    enqueue_table_full = 1
    include_enqueued = 2
    include_readerror = 3
    include_writeerror = 4
    OTHERS = 5.

    * Write the beautiful program code to ClipBoard from internal table
    CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
    data = mtab_jnc_prog[]
    CHANGING
    rc = myrc.

    LOOP AT mtab_jnc_prog.
    IF mtab_jnc_prog = space.
    SKIP 1.
    ENDIF.
    WRITE: / mtab_jnc_prog.
    ENDLOOP. " LOOP AT MTAB_JNC_PROG


    *---------------------------------------------------------------------*
    * FORM CREATE_CONDENSED_TABLE *
    *---------------------------------------------------------------------*
    * Create a table that has all statements condensed onto 1 line *
    *---------------------------------------------------------------------*
    FORM create_condensed_table
    TABLES ftab_old_prog STRUCTURE mtab_old_prog
    ftab_long_line STRUCTURE mtab_long_line.

    DATA:
    * Structure to hold program code/comment
    BEGIN OF fstr_line,
    code(172) TYPE c, " Program Code
    comment(172) TYPE c, " Inline comments
    END OF fstr_line.

    LOOP AT ftab_old_prog.

    IF ftab_long_line-start = 0.
    ftab_long_line-start = ftab_long_line-end + 1.
    CLEAR ftab_long_line-end.
    ENDIF.

    * Strip off any inline comments so they do not get in the way
    * If comments are not separated, then words in the comments could
    * look like keywords, and cause problems
    SPLIT ftab_old_prog-line AT `"` INTO fstr_line-code fstr_line-comment.

    * Align all statements to be left justified
    SHIFT fstr_line-code LEFT DELETING LEADING space.

    * Put all lines that make up a single statement into one field
    * This will make it easier to isolate key words. For example, if you
    * want to process a TABLES statement, but exclude the TABLES part of a
    * function call, or a subroutine call.
    CONCATENATE ftab_long_line-code fstr_line-code
    INTO ftab_long_line-code SEPARATED BY space.

    IF fstr_line-code CA `.` OR " Period means end of statement
    fstr_line-code(1) = `*` OR " Comment Line
    fstr_line-code CO space. " Blank Line
    * Keep track of the table index that the statement ends on
    ftab_long_line-end = sy-tabix.
    * Remove delimiter from concatenation of fields
    SHIFT ftab_long_line-code LEFT BY 1 PLACES.

    APPEND ftab_long_line.

    CLEAR: ftab_long_line-code, ftab_long_line-start.

    * Don`t clear out fstr_long_line-end yet. It is used to calc
    * fstr_long_line-start.
    ENDIF.

    ENDLOOP. " LOOP AT FTAB_OLD_PROG
    ENDFORM. " FORM CREATE_CONDENSED_TABLE

    *---------------------------------------------------------------------*
    * FORM FORMAT_PROGRAM *
    *---------------------------------------------------------------------*
    FORM format_program.

    DATA: lstr_old_prog LIKE LINE OF mtab_old_prog.

    LOOP AT mtab_long_line.

    TRANSLATE mtab_long_line-code TO UPPER CASE.

    IF mtab_long_line-code(1) EQ `*`. " Do not modify Comment Lines

    LOOP AT mtab_old_prog FROM mtab_long_line-start
    TO mtab_long_line-end.

    mtab_new_prog-line = mtab_old_prog-line.

    APPEND mtab_new_prog.

    ENDLOOP. " LOOP AT MTAB_OLD_PROG

    ELSEIF mtab_long_line-code(6) EQ `TABLES`.

    * Reformat any TABLES statements. Will only reformat when TABLES
    * is at the start of the statement. Will not try to get table
    * descriptions for CALL FUNCTIONS or FORM/PERFORMs

    * Get the table names from mstr_long_line.
    PERFORM get_table_names_from_statement TABLES mtab_tabname
    USING mtab_long_line-code.
    * Find the descriptions for each table
    PERFORM get_table_descriptions TABLES mtab_tabname.

    * create the new statement
    PERFORM build_new_tables_statement USING mtab_long_line.

    ELSE. " All other modifications to the code handled here

    LOOP AT mtab_old_prog FROM mtab_long_line-start
    TO mtab_long_line-end.

    * Remove extra spaces from line for comparisons
    lstr_old_prog-line = mtab_old_prog-line.
    CONDENSE lstr_old_prog-line.
    TRANSLATE lstr_old_prog-line TO UPPER CASE.

    IF lstr_old_prog-line CS `"`. " Comments
    mtab_new_prog-line = mtab_old_prog-line.
    ELSE.
    IF lstr_old_prog-line CS ` LIKE ` OR
    lstr_old_prog-line CS ` TYPE ` OR
    lstr_old_prog-line CS ` FOR ` OR
    lstr_old_prog-line CS `~`. "jnc OpenSQL table~column


    PERFORM get_for_like_comment USING mtab_old_prog
    CHANGING mtab_new_prog.

    ELSEIF lstr_old_prog-line(8) = 'LOOP AT'.

    * save table name into a queue
    PERFORM enqueue_itab_name USING mtab_long_line-code.
    mtab_new_prog-line = mtab_old_prog-line.

    ELSEIF lstr_old_prog-line(7) = `ENDLOOP`.

    * get name off of queue and add it as a comment to the ENDLOOP line
    PERFORM add_comment_to_endloop USING mtab_old_prog-line
    CHANGING mtab_new_prog-line.

    ELSEIF lstr_old_prog-line(7) EQ 'SELECT' AND
    lstr_old_prog-line(13) NE 'SELECT SINGLE'.

    * save table name into a queue
    PERFORM enqueue_tab_name USING mtab_old_prog-line.
    mtab_new_prog-line = mtab_old_prog-line.
    ELSEIF lstr_old_prog-line(9) = `ENDSELECT`.

    * get name off of queue and add it as a comment to the ENDSELECT
    PERFORM add_comment_to_select USING mtab_old_prog-line
    CHANGING mtab_new_prog-line.

    ELSEIF lstr_old_prog-line(5) = 'FORM'.

    * save form name into a queue
    PERFORM enqueue_form_name USING mtab_old_prog-line.
    mtab_new_prog-line = mtab_old_prog-line.

    ELSEIF lstr_old_prog-line(7) = `ENDFORM`.

    * get name off of queue and add it as a comment to the ENDFORM
    PERFORM add_comment_to_endform USING mtab_old_prog-line
    CHANGING mtab_new_prog-line.
    ELSE. " Any other lines
    mtab_new_prog-line = mtab_old_prog-line.
    ENDIF.
    ENDIF.

    APPEND mtab_new_prog.

    ENDLOOP. " LOOP AT MTAB_OLD_PROG
    ENDIF.
    ENDLOOP. " LOOP AT MTAB_LONG_LINE

    ENDFORM. " FORM FORMAT_PROGRAM


    *---------------------------------------------------------------------*
    * FORM GET_TABLE_NAMES_FROM_STATEMENT *
    *---------------------------------------------------------------------*
    FORM get_table_names_from_statement TABLES ftab_tabname
    STRUCTURE mtab_tabname
    USING fc_statement.

    CLEAR ftab_tabname.
    REFRESH ftab_tabname.

    REPLACE `TABLES` WITH space INTO fc_statement.
    TRANSLATE fc_statement USING `. `. " Replace periods
    TRANSLATE fc_statement USING `, `. " Replace commas
    TRANSLATE fc_statement USING `: `. " Replace colons

    CONDENSE fc_statement. " Remove all extra spaces

    SPLIT fc_statement AT space INTO TABLE ftab_tabname.

    ENDFORM. " FORM GET_TABLE_NAMES_FROM_STATEMENT


    *---------------------------------------------------------------------*
    * FORM GET_TABLE_DESCRIPTIONS *
    *---------------------------------------------------------------------*
    FORM get_table_descriptions TABLES ftab_tabname STRUCTURE mtab_tabname.

    LOOP AT ftab_tabname.
    SELECT SINGLE * FROM dd02t
    WHERE tabname = ftab_tabname-tabname
    AND ddlanguage = sy-langu.

    IF sy-subrc = 0.
    ftab_tabname-tabdesc = dd02t-ddtext.
    MODIFY ftab_tabname.
    ENDIF.

    ENDLOOP. " LOOP AT FTAB_TABNAME
    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM BUILD_NEW_TABLES_STATEMENT *
    *---------------------------------------------------------------------*
    FORM build_new_tables_statement USING fstr_long_line LIKE
    mtab_long_line.

    DATA: lc_sep(1) TYPE c,
    li_rows TYPE i,
    wordlen TYPE i.

    DESCRIBE TABLE mtab_tabname LINES li_rows.

    mtab_new_prog-line = `TABLES:`.
    APPEND mtab_new_prog.

    LOOP AT mtab_tabname.
    IF sy-tabix = li_rows.
    lc_sep = `.`.
    ELSE.
    lc_sep = `,`.
    ENDIF.

    wordlen = STRLEN( mtab_tabname-tabname ).

    IF wordlen < 12.
    wordlen = 12 - wordlen.
    ELSE.
    wordlen = 1.
    ENDIF.

    CONCATENATE `^^` mtab_tabname-tabname lc_sep myhats+0(wordlen) ` " ` mtab_tabname-tabdesc
    INTO mtab_new_prog.

    TRANSLATE mtab_new_prog USING `^ `.

    APPEND mtab_new_prog.

    ENDLOOP. " LOOP AT MTAB_TABNAME

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM GET_FOR/LIKE_COMMENT *
    *---------------------------------------------------------------------*
    FORM get_for_like_comment USING value(f_old_prog) LIKE mtab_old_prog
    CHANGING f_new_prog LIKE mtab_new_prog
    .

    DATA:
    lc_dummy(1) TYPE c,
    lc_tabname(40) TYPE c,
    wordlen TYPE i,
    ltab_nametab LIKE dntab OCCURS 0 WITH HEADER LINE,
    lstr_old_prog LIKE LINE OF mtab_old_prog,

    BEGIN OF lstr_field,
    tabname LIKE dd02t-tabname, " Table name
    fldname LIKE dd02t-tabname, " Table name
    END OF lstr_field.

    lstr_old_prog-line = f_old_prog. " SAVE input

    TRANSLATE f_old_prog TO UPPER CASE.
    CONDENSE f_old_prog.

    IF f_old_prog-line CA `"` OR " Line already commented
    f_old_prog-line(1) = `*`.
    f_new_prog = f_old_prog.
    RETURN.

    ELSEIF f_old_prog CS ` LIKE `.
    SPLIT f_old_prog AT ` LIKE ` INTO lc_dummy lc_tabname.

    ELSEIF f_old_prog CS ` TYPE `.
    SPLIT f_old_prog AT ` TYPE ` INTO lc_dummy lc_tabname.

    ELSEIF f_old_prog CS ` FOR `.
    SPLIT f_old_prog AT ` FOR ` INTO lc_dummy lc_tabname.

    ELSEIF f_old_prog CS `~`.
    MOVE f_old_prog TO lc_tabname.
    CONDENSE lc_tabname.
    SPLIT lc_tabname AT `~` INTO lstr_field-tabname lstr_field-fldname.

    ELSE.
    f_new_prog = lstr_old_prog-line.
    RETURN.
    ENDIF.

    * If there is anything following the table-field in a LIKE or FOR clause
    * it will be removed so that only the table-field remains
    IF NOT f_old_prog CS `~`.
    CONDENSE lc_tabname.

    TRANSLATE lc_tabname USING `. `. " Remove periods
    TRANSLATE lc_tabname USING `, `. " Remove commas
    CONDENSE lc_tabname. " Remove extra white space

    SPLIT lc_tabname AT `-` INTO lstr_field-tabname lstr_field-fldname.

    * The system variables are actually defined in DDIC structure SYST
    IF lstr_field-tabname = `SY`.
    lstr_field-tabname = `SYST`.
    ENDIF.
    ENDIF.

    TRANSLATE lstr_field-tabname TO UPPER CASE.
    TRANSLATE lstr_field-fldname TO UPPER CASE.

    CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
    tabname = lstr_field-tabname
    TABLES
    nametab = ltab_nametab
    EXCEPTIONS
    internal_error = 1
    table_has_no_fields = 2
    table_not_activ = 3
    no_texts_found = 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.

    READ TABLE ltab_nametab
    WITH KEY tabname = lstr_field-tabname
    fieldname = lstr_field-fldname.

    IF sy-subrc = 0.

    wordlen = STRLEN( lstr_old_prog-line ).

    IF wordlen < 45.
    wordlen = 45 - wordlen.
    ELSE.
    wordlen = 1.
    ENDIF.

    CONCATENATE lstr_old_prog-line myhats+0(wordlen) ` " ` ltab_nametab-fieldtext
    INTO f_new_prog.

    TRANSLATE mtab_new_prog USING `^ `.

    ELSE.
    f_new_prog = lstr_old_prog-line.
    ENDIF.

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS

    *---------------------------------------------------------------------*
    * FORM ENQUEUE_ITAB_NAME *
    *---------------------------------------------------------------------*
    FORM enqueue_itab_name USING value(f_line) LIKE mtab_long_line-code.

    DATA:
    lc_dummy(1) TYPE c,
    lc_itab(40) TYPE c.

    TRANSLATE f_line TO UPPER CASE.

    SPLIT f_line AT `LOOP AT ` INTO lc_dummy lc_itab.

    SPLIT lc_itab AT space INTO lc_itab lc_dummy.

    TRANSLATE lc_itab USING `. `.
    CONDENSE lc_itab.

    mtab_itab_names = lc_itab.

    * Always have the most recent LOOP AT table as the first entry in the
    * queue
    INSERT mtab_itab_names INDEX 1.

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM ADD_COMMENT_TO_ENDLOOP *
    *---------------------------------------------------------------------*
    FORM add_comment_to_endloop USING fstr_long_line LIKE mtab_old_prog-line
    CHANGING f_prog_line LIKE mtab_new_prog-line
    .

    IF mtab_old_prog-line NA `"`. " No comments
    * Get the internal table from the queue
    READ TABLE mtab_itab_names INDEX 1.
    CONCATENATE mtab_old_prog-line ` "` `LOOP AT` mtab_itab_names-tabname
    INTO f_prog_line SEPARATED BY space.

    * Dequeue the itab name
    DELETE mtab_itab_names INDEX 1.
    ELSE.
    f_prog_line = mtab_old_prog-line.
    ENDIF.
    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM ENQUEUE_TAB_NAME *
    *---------------------------------------------------------------------*
    FORM enqueue_tab_name USING f_line LIKE mtab_old_prog-line.

    DATA:
    lc_dummy(1) TYPE c,
    lc_tab(40) TYPE c.

    TRANSLATE f_line TO UPPER CASE.

    SPLIT f_line AT ` FROM ` INTO lc_dummy lc_tab.

    CONDENSE lc_tab. " Remove leading/trailing extra spaces

    SPLIT lc_tab AT space INTO lc_tab lc_dummy.

    TRANSLATE lc_tab USING `. `.
    CONDENSE lc_tab.

    mtab_tab_names = lc_tab.

    * Always have the most recent LOOP AT table as the first entry in the
    * queue
    INSERT mtab_tab_names INDEX 1.

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM ADD_COMMENT_TO_SELECT *
    *---------------------------------------------------------------------*
    FORM add_comment_to_select USING fstr_long_line LIKE mtab_old_prog-line
    CHANGING f_prog_line.

    IF mtab_old_prog-line NA `"`. " No comments
    * Get the table from the queue
    READ TABLE mtab_tab_names INDEX 1.
    CONCATENATE mtab_old_prog-line ` "` `SELECT FROM`
    mtab_tab_names-tabname
    INTO f_prog_line SEPARATED BY
    space.

    * Dequeue the tab name
    DELETE mtab_tab_names INDEX 1.
    ELSE.
    f_prog_line = mtab_old_prog-line.
    ENDIF.

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM ADD_COMMENT_TO_ENDFORM *
    *---------------------------------------------------------------------*
    FORM add_comment_to_endform USING fstr_long_line LIKE
    mtab_old_prog-line
    CHANGING f_prog_line.

    IF mtab_old_prog-line NA `"`. " No comments
    * Get the table from the queue
    READ TABLE mtab_form_names INDEX 1.
    CONCATENATE mtab_old_prog-line ` "` `FORM` mtab_form_names-tabname
    INTO f_prog_line SEPARATED BY space.

    * Dequeue the form name
    DELETE mtab_form_names INDEX 1.
    ELSE.
    f_prog_line = mtab_old_prog-line.
    ENDIF.

    ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


    *---------------------------------------------------------------------*
    * FORM ENQUEUE_FORM_NAME *
    *---------------------------------------------------------------------*
    FORM enqueue_form_name USING f_line.

    DATA:
    lc_dummy(1) TYPE c,
    lc_tab(40) TYPE c.

    TRANSLATE f_line TO UPPER CASE.

    SPLIT f_line AT `FORM ` INTO lc_dummy
    lc_tab.

    CONDENSE lc_tab. " Remove leading/trailing extra spaces

    SPLIT lc_tab AT space INTO lc_tab lc_dummy.

    TRANSLATE lc_tab USING `. `.
    CONDENSE lc_tab.

    mtab_form_names = lc_tab.

    * Always have the most recent LOOP AT table as the first entry in the
    * queue
    INSERT mtab_form_names INDEX 1.

    ENDFORM. " FORM ENQUEUE_FORM_NAME

    simple tree in abap report program 4

    REPORT ZRJNTRIAL_TREE
    LINE-COUNT 65
    LINE-SIZE 80
    NO STANDARD PAGE
    HEADING.


    DATA: BEGIN OF ITEMS OCCURS 100,
    ID(10),
    PARENT_ID(10),
    TEXT(20),
    SYMBOL,
    END OF ITEMS,
    TABIX_STACK LIKE SY-TABIX OCCURS 10 WITH HEADER LINE,
    ITEMS_SHOW LIKE ITEMS OCCURS 100 WITH HEADER LINE.
    INCLUDE .

    * append sample items (mixed order)
    PERFORM APPEND_ITEM USING:
    '1' '' 'Food',
    '2' '' 'Drinks',
    '12' '9' 'Jack Daniels',
    '17' '11' 'Bosch',
    '3' '' 'Tools',
    '4' '1' 'Meat',
    '16' '11' 'Metabo',
    '5' '1' 'Chocolate',
    '6' '2' 'Alcoholic',
    '8' '4' 'Pork',
    '10' '5' 'Milka',
    '11' '3' 'Drills',
    '13' '9' 'Jim Beam',
    '7' '4' 'Beef',
    '14' '2' 'Non-alcoholic',
    '35' '31' 'Teran',
    '9' '6' 'Whiskey',
    '15' '14' 'Coca-cola',
    '18' '6' 'Wine',
    '28' '18' 'Croatia',
    '33' '28' 'Slavonia',
    '34' '28' 'Istria',
    '29' '18' 'Hungary',
    '30' '29' 'Tokaj',
    '19' '33' 'Enjingi',
    '20' '33' 'Zdjelarevic',
    '22' '19' 'Riesling',
    '23' '19' 'Chardonnay',
    '24' '20' 'Riesling',
    '32' '31' 'Malvazija',
    '25' '20' 'Merlot',
    '31' '34' 'Tomasevic'.

    * show initial list (items with level 0 - parentless items)
    LOOP AT ITEMS WHERE PARENT_ID = ''.
    MOVE-CORRESPONDING ITEMS TO ITEMS_SHOW.
    ITEMS_SHOW-SYMBOL = '+'.
    APPEND ITEMS_SHOW.
    ENDLOOP.
    PERFORM PRINT_TREE TABLES ITEMS_SHOW.

    * at line-selection - when the node is opened/closed or item double-clk
    AT LINE-SELECTION.
    READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. "see 'hide'
    IF SY-SUBRC = 0. "item has children - expand or collapse
    SY-LSIND = 0.
    PERFORM EXPAND_COLLAPSE USING ITEMS_SHOW-ID.
    PERFORM PRINT_TREE TABLES ITEMS_SHOW.
    ELSE. "item has NO children - perform some action
    READ TABLE ITEMS WITH KEY ID = ITEMS_SHOW-ID.
    WRITE: 'Action performed on item "' NO-GAP, ITEMS-TEXT NO-GAP,
    '", id.', ITEMS-ID.
    ENDIF.

    * form print_tree
    FORM PRINT_TREE TABLES ITEMS STRUCTURE ITEMS.
    DATA: V_TABIX LIKE SY-TABIX,
    START_TABIX LIKE SY-TABIX,
    V_LEVEL LIKE SY-TFILL,
    V_OFFSET TYPE I,
    V_ID LIKE ITEMS-ID,
    V_PARENT_ID LIKE ITEMS-PARENT_ID,
    V_PARENT_ID_FOR_VLINE LIKE ITEMS-PARENT_ID,
    V_PREV_LEVEL TYPE I,
    V_ITEMS_COUNT LIKE SY-TFILL,
    V_VLINES_STRING(200).
    CHECK NOT ITEMS[] IS INITIAL.
    SORT ITEMS BY PARENT_ID ID.
    READ TABLE ITEMS INDEX 1.
    V_PARENT_ID = ITEMS-PARENT_ID.
    START_TABIX = 1.
    REFRESH TABIX_STACK.
    DO.
    LOOP AT ITEMS FROM START_TABIX.
    V_TABIX = START_TABIX = SY-TABIX."remember current index
    V_ID = ITEMS-ID.
    V_PARENT_ID_FOR_VLINE = ITEMS-PARENT_ID.
    * decrease level and exit loop if parent not the same as previous
    IF ITEMS-PARENT_ID NE V_PARENT_ID.
    PERFORM READ_FROM_STACK CHANGING START_TABIX. "level = NoOfRecs
    READ TABLE ITEMS INDEX START_TABIX.
    V_PARENT_ID = ITEMS-PARENT_ID.
    ADD 1 TO START_TABIX. "next loop starts from parent index + 1
    * clear vline
    IF V_LEVEL > 1.
    V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3.
    IF V_LEVEL = 1. V_OFFSET = 1. ENDIF.
    V_VLINES_STRING+V_OFFSET = ' '.
    ENDIF.
    EXIT.
    ENDIF.
    V_PARENT_ID = ITEMS-PARENT_ID.
    * write item
    FORMAT COLOR OFF.
    DESCRIBE TABLE TABIX_STACK LINES V_LEVEL."level is no of
    *StackRecs
    WRITE: / V_VLINES_STRING.
    V_OFFSET = V_LEVEL * 3.
    IF V_LEVEL NE 0.
    IF V_PREV_LEVEL < V_LEVEL.
    WRITE: AT V_OFFSET '|', / ''.
    WRITE: / V_VLINES_STRING.
    ENDIF.
    V_OFFSET = V_LEVEL * 3.
    WRITE AT V_OFFSET '|--'.
    ENDIF.
    V_OFFSET = V_OFFSET + 3.
    CASE ITEMS-SYMBOL.
    WHEN '+'.
    WRITE AT V_OFFSET SYM_PLUS_FOLDER AS SYMBOL
    COLOR 4 INTENSIFIED HOTSPOT.
    WHEN '-'.
    WRITE AT V_OFFSET SYM_MINUS_FOLDER AS SYMBOL
    COLOR 4 INTENSIFIED HOTSPOT.
    WHEN OTHERS. FORMAT COLOR 5.
    ENDCASE.
    WRITE: ITEMS-TEXT.
    V_PREV_LEVEL = V_LEVEL.
    HIDE: ITEMS-ID.
    ADD 1 TO V_ITEMS_COUNT.
    READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS-ID.
    * increase level and exit loop if item has children
    IF SY-SUBRC = 0.
    START_TABIX = SY-TABIX.
    APPEND V_TABIX TO TABIX_STACK. "level is no of recs in stack
    V_PARENT_ID = ITEMS-PARENT_ID.
    * set vline
    V_TABIX = V_TABIX + 1.
    READ TABLE ITEMS INDEX V_TABIX.
    V_OFFSET = 2 + ( V_LEVEL - 1 ) * 3.
    IF V_LEVEL > 0.
    IF ITEMS-PARENT_ID = V_PARENT_ID_FOR_VLINE AND SY-SUBRC = 0.
    V_VLINES_STRING+V_OFFSET = '|'.
    ELSE.
    V_VLINES_STRING+V_OFFSET = ' '.
    ENDIF.
    ENDIF.
    EXIT.
    ENDIF.
    * at last - decrease level
    AT LAST.
    * clear vline
    IF V_LEVEL > 1.
    V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3.
    IF V_LEVEL = 1. V_OFFSET = 1. ENDIF.
    V_VLINES_STRING+V_OFFSET = ' '.
    ENDIF.
    " next loop starts from parent index, not parent index + 1
    " because of different parents level will decrease anyway
    PERFORM READ_FROM_STACK CHANGING START_TABIX.
    APPEND START_TABIX TO TABIX_STACK. "must return index to stack
    ENDAT.
    ENDLOOP.
    DESCRIBE TABLE ITEMS.
    IF START_TABIX > SY-TFILL OR V_ITEMS_COUNT >= SY-TFILL.
    EXIT.
    ENDIF.
    ENDDO.
    ENDFORM.

    * form expand_collapse
    FORM EXPAND_COLLAPSE USING VALUE(V_ID).
    DATA: V_NO_MORE_ORPHANS,
    ITEMS_TEMP LIKE ITEMS OCCURS 100 WITH HEADER LINE.
    DELETE ITEMS_SHOW WHERE PARENT_ID = V_ID. "try to collapse
    IF SY-SUBRC = 0. "succesfull first collapse
    DO. "cascade collapse - delete 'orphans' that are left
    REFRESH ITEMS_TEMP.
    MOVE ITEMS_SHOW[] TO ITEMS_TEMP[].
    SORT ITEMS_TEMP BY ID.
    V_NO_MORE_ORPHANS = 'X'.
    LOOP AT ITEMS_SHOW WHERE PARENT_ID NE ''.
    READ TABLE ITEMS_TEMP WITH KEY ID = ITEMS_SHOW-PARENT_ID
    BINARY SEARCH TRANSPORTING NO FIELDS.
    IF SY-SUBRC NE 0. "no parent - it's an orphan
    CLEAR V_NO_MORE_ORPHANS.
    DELETE ITEMS_SHOW.
    ENDIF.
    ENDLOOP.
    IF V_NO_MORE_ORPHANS = 'X'. EXIT. ENDIF.
    ENDDO.
    ITEMS_SHOW-SYMBOL = '+'.
    MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID.
    ELSE. "unsuccessfull collapse - expand
    ITEMS_SHOW-SYMBOL = '-'.
    MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID.
    LOOP AT ITEMS WHERE PARENT_ID = V_ID. "show children
    APPEND ITEMS TO ITEMS_SHOW.
    ENDLOOP.
    LOOP AT ITEMS_SHOW WHERE PARENT_ID = V_ID. "check grandchildren
    READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID.
    IF SY-SUBRC = 0.
    ITEMS_SHOW-SYMBOL = '+'.
    ELSE.
    ITEMS_SHOW-SYMBOL = ''.
    ENDIF.
    MODIFY ITEMS_SHOW.
    ENDLOOP.
    ENDIF.
    ENDFORM.

    * form append_item
    FORM APPEND_ITEM USING VALUE(ID) VALUE(PARENT_ID) VALUE(TEXT).
    ITEMS-ID = ID.
    ITEMS-PARENT_ID = PARENT_ID.
    ITEMS-TEXT = TEXT.
    APPEND ITEMS.
    ENDFORM.

    * form read_from_stack
    FORM READ_FROM_STACK CHANGING TABIX LIKE SY-TABIX.
    DESCRIBE TABLE TABIX_STACK.
    CHECK SY-TFILL NE 0.
    READ TABLE TABIX_STACK INDEX SY-TFILL.
    TABIX = TABIX_STACK.
    DELETE TABIX_STACK INDEX SY-TFILL.
    ENDFORM.

    tab strips for the selection screen

    REPORT ZTABSTRIPS LINE-SIZE 120
    NO STANDARD PAGE HEADING.

    TABLES: ekko, ekpo, eket, marc, t134h.

    *---------------------------------------------------------------------*
    * Tab Strips 1
    *---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
    SELECTION-SCREEN BEGIN OF BLOCK vendor WITH FRAME TITLE text-t00.
    SELECT-OPTIONS vendor FOR ekko-lifnr.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (10) text-m01.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN SKIP.
    SELECT-OPTIONS vplant FOR ekko-reswk.
    SELECTION-SCREEN END OF BLOCK vendor.
    SELECTION-SCREEN END OF SCREEN 101.
    *---------------------------------------------------------------------*
    * Tab Strips 2
    *---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN.
    SELECTION-SCREEN BEGIN OF BLOCK data1 WITH FRAME TITLE text-t02.
    SELECT-OPTIONS: busarea FOR t134h-gsber,
    plant FOR ekpo-werks,
    puorg FOR ekko-ekorg.
    SELECTION-SCREEN END OF BLOCK data1.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK data2 WITH FRAME TITLE text-t03.
    SELECT-OPTIONS sched FOR ekko-ebeln.
    SELECT-OPTIONS matl FOR ekpo-matnr.
    SELECTION-SCREEN END OF BLOCK data2.
    SELECTION-SCREEN END OF SCREEN 102.
    *---------------------------------------------------------------------*
    * Tab Strips 3
    *---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF SCREEN 103 AS SUBSCREEN.
    SELECTION-SCREEN BEGIN OF BLOCK rype WITH FRAME TITLE text-t04.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS del RADIOBUTTON GROUP one.
    SELECTION-SCREEN COMMENT 4(35) text-c05 FOR FIELD del.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS fix RADIOBUTTON GROUP one.
    SELECTION-SCREEN COMMENT 4(35) text-c06 FOR FIELD fix.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK rype.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK interval WITH FRAME TITLE text-t05.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS mon RADIOBUTTON GROUP two.
    SELECTION-SCREEN COMMENT 4(15) text-c01 FOR FIELD mon.
    PARAMETERS evalmon TYPE spbup.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS wek RADIOBUTTON GROUP two.
    SELECTION-SCREEN COMMENT 4(15) text-c02 FOR FIELD wek.
    PARAMETERS evalweek TYPE sptag.
    SELECTION-SCREEN COMMENT 35(30) text-i01.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK interval.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK type WITH FRAME TITLE text-t01.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS ext RADIOBUTTON GROUP thr.
    SELECTION-SCREEN COMMENT 4(15) text-c08 FOR FIELD int.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS int RADIOBUTTON GROUP thr.
    SELECTION-SCREEN COMMENT 4(15) text-c07 FOR FIELD ext.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK type.
    SELECTION-SCREEN BEGIN OF BLOCK pre WITH FRAME TITLE text-t06.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS vn RADIOBUTTON GROUP slv.
    SELECTION-SCREEN COMMENT 4(15) text-c09 FOR FIELD vn.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS bp RADIOBUTTON GROUP slv.
    SELECTION-SCREEN COMMENT 4(17) text-c10 FOR FIELD bp.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK pre.
    SELECTION-SCREEN END OF SCREEN 103.

    SELECTION-SCREEN BEGIN OF TABBED BLOCK uno FOR 20 LINES.
    SELECTION-SCREEN TAB (15) name1 USER-COMMAND ucomm1
    DEFAULT SCREEN 101.
    SELECTION-SCREEN TAB (17) name2 USER-COMMAND ucomm2
    DEFAULT SCREEN 102.
    SELECTION-SCREEN TAB (23) name3 USER-COMMAND ucomm3
    DEFAULT SCREEN 103.
    SELECTION-SCREEN END OF BLOCK uno.

    INITIALIZATION.
    name1 = text-n01.
    name2 = text-n02.
    name3 = text-n03.

    simple alv tree report program 3

    REPORT Ztree_TEST_PGM.

    Type-pools : fibs,stree.

    data : t_node type snodetext.

    data : node_tab like t_node occurs 0 with header line.

    clear : node_tab, node_tab[].

    node_tab-type = 'T'.
    node_tab-name = 'Earth'.
    node_tab-tlevel = '01'.
    node_tab-nlength = '5'.
    node_tab-color = '4'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 3.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'Europe'.
    node_tab-tlevel = '02'.
    node_tab-nlength = '6'.
    node_tab-color = '1'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 4.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'Germany'.
    node_tab-tlevel = '03'.
    node_tab-nlength = '7'.
    node_tab-color = '4'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 4.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'Berlin'.
    node_tab-tlevel = '04'.
    node_tab-nlength = '6'.
    node_tab-color = '4'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 3.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'Asia'.
    node_tab-tlevel = '02'.
    node_tab-nlength = '4'.
    node_tab-color = '1'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 3.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'India'.
    node_tab-tlevel = '03-'.
    node_tab-nlength = '5'.
    node_tab-color = '1'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 3.
    append node_tab.
    clear node_tab.

    node_tab-type = 'P'.
    node_tab-name = 'Bombay'.
    node_tab-tlevel = '04-'.
    node_tab-nlength = '6'.
    node_tab-color = '1'.
    node_tab-text = 'Hello'.
    node_tab-tlength ='5'.
    node_tab-tcolor = 3.
    append node_tab.
    clear node_tab.


    CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
    NODETAB = node_tab .

    DATA: type_mapping TYPE stree_ctl_type_mapping_tab.
    DATA: wa_type TYPE stree_ctl_type_mapping.
    CLEAR: type_mapping[].

    wa_type-type = 'A'.
    wa_type-icon = '@BL@'.
    APPEND wa_type TO type_mapping.

    CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
    USE_CONTROL = 'L'.

    simple tree structure in abap report2

    REPORT ZVVMUR12 .

    TABLES: KNVH.

    TYPES: BEGIN OF WORKTYPE,
    LEVEL(2),
    HKUNNR LIKE KNVH-KUNNR,
    KUNNR LIKE KNVH-HKUNNR,
    END OF WORKTYPE.

    DATA: IT_KNVH TYPE TABLE OF WORKTYPE,
    WA_KNVH LIKE LINE OF IT_KNVH,
    IT_TEMP TYPE TABLE OF WORKTYPE,
    WA_TEMP LIKE LINE OF IT_TEMP,
    IT_WORK TYPE TABLE OF WORKTYPE,
    WA_WORK LIKE LINE OF IT_WORK.

    DATA : BEGIN OF IT_NODES OCCURS 0.
    INCLUDE STRUCTURE SNODETEXT.
    DATA : END OF IT_NODES.

    CONSTANTS: NUMBER_OF_LEVELS TYPE I VALUE 6.
    PARAMETER: P_HKUNNR LIKE KNVH-HKUNNR.

    START-OF-SELECTION.

    * Parent = 1. hierarchy node
    WA_TEMP-KUNNR = P_HKUNNR.
    APPEND WA_TEMP TO IT_TEMP.
    WA_WORK-KUNNR = WA_TEMP-KUNNR.
    WA_WORK-LEVEL = 1.
    APPEND WA_WORK TO IT_WORK.

    * Reading customer hierarchy (max. 6 level)
    DO NUMBER_OF_LEVELS TIMES.

    CHECK NOT IT_TEMP IS INITIAL.

    SELECT KUNNR HKUNNR
    FROM KNVH
    INTO CORRESPONDING FIELDS OF TABLE IT_KNVH
    FOR ALL ENTRIES IN IT_TEMP
    WHERE HKUNNR = IT_TEMP-KUNNR.

    LOOP AT IT_KNVH INTO WA_KNVH.
    WA_KNVH-LEVEL = SY-INDEX + 1.
    APPEND WA_KNVH TO IT_WORK.
    ENDLOOP.

    IT_TEMP[] = IT_KNVH[].

    ENDDO.

    * Hierarchy nodes -> tree control
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 1.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 2 AND
    HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 3 AND
    HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 4 AND
    HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 5 AND
    HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 6 AND
    HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    ENDLOOP.
    ENDLOOP.
    ENDLOOP.
    ENDLOOP.
    ENDLOOP.
    ENDLOOP.

    * Making the tree control
    CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
    NODETAB = IT_NODES
    EXCEPTIONS
    TREE_FAILURE = 1.

    * Display the tree control
    DATA : F15 TYPE C.
    CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
    CALLBACK_PROGRAM = SY-REPID
    IMPORTING
    F15 = F15 .


    FORM MAKE_NODE.
    IT_NODES-NAME = WA_WORK-KUNNR.
    IT_NODES-COLOR = 1.
    IT_NODES-INTENSIV = 1.
    IT_NODES-TEXT = WA_WORK-KUNNR.
    IT_NODES-TLENGTH = 16.
    IT_NODES-TLEVEL = WA_WORK-LEVEL.
    IT_NODES-TCOLOR = 1.
    IT_NODES-TINTENSIV = 1.
    APPEND IT_NODES.
    ENDFORM.

    simple tree structure in abap

    *
    * An ABAP reporting tree program that allows the user to press enter or double click on
    * any line. The report is updated with new internal table data and re-written. The cursor
    * and paging returns to the exact same line the user was on, even though the report was
    * re-written from the internal table. Input fields are filled with data based on ENTER of
    * DOUBLE CLICK. [+] and [-] is displayed on each line and changes if user selects to
    * expand/collapse.
    *
    * Create a gui status (8000) with Functions Keys
    * ENTER = ENTE
    * BACK = BACK
    * EXIT = %EX
    * CANCEL = RW
    * PICK = F2
    * EXPAND ALL = EXPA
    * COLLAPSE ALL = COLA
    *
    * Written by : SAP Basis, ABAP Programming and Other IMG Stuff
    * http://www.sap-img.com
    *
    REPORT ZTREE NO STANDARD PAGE HEADING
    LINE-COUNT 65
    LINE-SIZE 80.

    DATA: BEGIN OF IT_DATA OCCURS 0,
    EXP(1) TYPE C,
    WERKS LIKE T001W-WERKS,
    MATNR LIKE MARA-MATNR,
    VALUE1(13) TYPE C,
    VALUE2(13) TYPE C,
    END OF IT_DATA.

    DATA: W_MATNR LIKE MARA-MATNR,
    W_COUNT TYPE I,
    G_FIELD(40) TYPE C.

    DATA: BEGIN OF PAGE,
    SCRLLINE LIKE SYST-LILLI, "scroll line to top of screen
    CURSLINE LIKE SYST-LILLI, "line to put cursor on
    HDRLINES TYPE I, "lines in header + 1
    TWOHDRS TYPE I, "two headers on screen
    CPOSTOP TYPE I, "position of cursor from top
    CPOSBOT TYPE I, "position of cursor from bottom
    CPOSIT TYPE I, "position on the screen
    PAGNO TYPE I, "pageno of line
    PGELINES TYPE I, "lines used so far
    END OF PAGE.

    START-OF-SELECTION.
    PERFORM BUILD_IT_DATA.

    END-OF-SELECTION.
    PERFORM WRITE_REPORT.

    TOP-OF-PAGE.
    PERFORM TOP_OF_PAGE.

    TOP-OF-PAGE DURING LINE-SELECTION.
    PERFORM TOP_OF_PAGE.

    AT LINE-SELECTION.
    G_FIELD = SPACE.
    GET CURSOR FIELD G_FIELD.
    PERFORM LINE_SELECTION.

    AT USER-COMMAND.
    G_FIELD = SPACE.
    GET CURSOR FIELD G_FIELD.
    PERFORM USER_COMMAND.

    *---------------------------------------------------------------------*
    * FORM BUILD_IT_DATA *
    *---------------------------------------------------------------------*
    FORM BUILD_IT_DATA.
    IT_DATA-WERKS = '0000'.
    WHILE IT_DATA-WERKS < '0100'.
    ADD '10' TO IT_DATA-WERKS.
    W_MATNR = 0.
    WHILE W_MATNR < 10.
    ADD 1 TO W_MATNR.
    IT_DATA-EXP = '+'.
    WRITE W_MATNR TO IT_DATA-MATNR.
    IF IT_DATA-WERKS = 10 AND W_MATNR = 1.
    WRITE 'ZTEST2' TO IT_DATA-VALUE1.
    WRITE 'Testing program 2' TO IT_DATA-VALUE2.
    ELSE.
    CLEAR: IT_DATA-VALUE1, IT_DATA-VALUE2.
    ENDIF.
    APPEND IT_DATA.
    ENDWHILE.
    ENDWHILE.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM WRITE_REPORT *
    *---------------------------------------------------------------------*
    FORM WRITE_REPORT.
    SET PF-STATUS '8000'.
    SYST-LSIND = '0'.
    LOOP AT IT_DATA.
    AT NEW WERKS.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: /1 SYST-VLINE NO-GAP,
    '[' NO-GAP,
    IT_DATA-EXP NO-GAP HOTSPOT ON,
    ']'.
    FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    WRITE: IT_DATA-WERKS,
    AT SYST-LINSZ SYST-VLINE.
    PAGE-PAGNO = SYST-PAGNO.
    HIDE: IT_DATA-WERKS, PAGE-PAGNO.
    ENDAT.
    IF IT_DATA-EXP = '-'.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    WRITE: /1 SYST-VLINE,
    8 IT_DATA-MATNR,
    IT_DATA-VALUE1 INPUT ON,
    IT_DATA-VALUE2 INPUT ON,
    AT SYST-LINSZ SYST-VLINE.
    HIDE: IT_DATA, PAGE-PAGNO.
    ENDIF.
    ENDLOOP.
    ULINE.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM USER_COMMAND *
    *---------------------------------------------------------------------*
    FORM USER_COMMAND.
    PERFORM SET_SCROLL_LINE.
    CASE SY-UCOMM.
    WHEN 'ENTE'.
    READ TABLE IT_DATA WITH KEY WERKS = IT_DATA-WERKS
    MATNR = IT_DATA-MATNR.
    IF SYST-SUBRC = 0.
    CASE G_FIELD.
    WHEN 'IT_DATA-VALUE1'.
    IF IT_DATA-VALUE1 <> SPACE.
    SUBMIT (IT_DATA-VALUE1) VIA SELECTION-SCREEN AND RETURN.
    ELSE.
    IT_DATA-VALUE1 = 'Enter 1 Press'(001).
    ENDIF.
    WHEN 'IT_DATA-VALUE2'.
    IT_DATA-VALUE2 = 'Enter 2 Press'(001).
    ENDCASE.
    MODIFY IT_DATA INDEX SYST-TABIX.
    ENDIF.
    PERFORM WRITE_REPORT.
    PERFORM POSITION_LIST.
    CASE G_FIELD.
    WHEN 'IT_DATA-EXP'.
    ADD 1 TO PAGE-CURSLINE.
    SET CURSOR FIELD 'IT_DATA-VALUE1' LINE PAGE-CURSLINE.
    WHEN 'IT_DATA-VALUE1'.
    SET CURSOR FIELD 'IT_DATA-VALUE1' LINE PAGE-CURSLINE.
    WHEN 'IT_DATA-VALUE2'.
    SET CURSOR FIELD 'IT_DATA-VALUE2' LINE PAGE-CURSLINE.
    ENDCASE.
    WHEN 'EXPA'.
    PERFORM SET_EXPAND USING '-'.
    PERFORM WRITE_REPORT.
    WHEN 'COLA'.
    PERFORM SET_EXPAND USING '+'.
    PERFORM WRITE_REPORT.
    ENDCASE.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM SET_EXPAND *
    *---------------------------------------------------------------------*
    FORM SET_EXPAND USING W_EXP.
    LOOP AT IT_DATA.
    IT_DATA-EXP = W_EXP.
    MODIFY IT_DATA INDEX SYST-TABIX.
    ENDLOOP.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM LINE_SELECTION *
    *---------------------------------------------------------------------*
    FORM LINE_SELECTION.
    PERFORM SET_SCROLL_LINE.
    READ TABLE IT_DATA WITH KEY WERKS = IT_DATA-WERKS
    MATNR = IT_DATA-MATNR.
    CASE G_FIELD.
    WHEN 'IT_DATA-EXP'.
    LOOP AT IT_DATA WHERE WERKS = IT_DATA-WERKS.
    IF IT_DATA-EXP = '-'.
    IT_DATA-EXP = '+'.
    ELSE.
    IT_DATA-EXP = '-'.
    ENDIF.
    MODIFY IT_DATA INDEX SYST-TABIX.
    ENDLOOP.
    WHEN 'IT_DATA-VALUE1'.
    IT_DATA-VALUE1 = 'Double Click'(004).
    MODIFY IT_DATA INDEX SYST-TABIX.
    WHEN 'IT_DATA-VALUE2'.
    IT_DATA-VALUE2 = 'Double Click'(004).
    MODIFY IT_DATA INDEX SYST-TABIX.
    ENDCASE.
    PERFORM WRITE_REPORT.
    PERFORM POSITION_LIST.
    CASE G_FIELD.
    WHEN 'IT_DATA-EXP'.
    ADD 1 TO PAGE-CURSLINE.
    SET CURSOR FIELD 'IT_DATA-VALUE1' LINE PAGE-CURSLINE.
    WHEN 'IT_DATA-VALUE1'.
    SET CURSOR FIELD 'IT_DATA-VALUE1' LINE PAGE-CURSLINE.
    WHEN 'IT_DATA-VALUE2'.
    SET CURSOR FIELD 'IT_DATA-VALUE2' LINE PAGE-CURSLINE.
    ENDCASE.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM SET_SCROLL_LINE *
    * determine the correct line to scroll the re-written report to, so *
    * that the user is returned to the same spot on the screen *
    * if user is mid way between pages, ie two headers are visable on the *
    * screen, check if they are on the secondary page and adjust the *
    * scroll variable accordingly so as not to jump up lines because the *
    * scroll variable will be out by the number of lines in the extra hdr *
    *---------------------------------------------------------------------*
    FORM SET_SCROLL_LINE.
    PAGE-CURSLINE = SYST-LILLI.
    PAGE-SCRLLINE = SYST-LILLI - ( SYST-CUROW - PAGE-HDRLINES ).
    PAGE-PGELINES = ( PAGE-PAGNO - 1 ) * SYST-LINCT.
    PAGE-CPOSTOP = ( PAGE-SCRLLINE + SYST-CUROW ) - PAGE-PGELINES.
    PAGE-CPOSBOT = ( PAGE-SCRLLINE - SYST-CUROW ) - PAGE-PGELINES.
    PAGE-CPOSIT = PAGE-CPOSTOP + PAGE-CPOSBOT.
    PAGE-TWOHDRS = PAGE-HDRLINES * 2.
    IF PAGE-CPOSIT LT PAGE-TWOHDRS.
    PAGE-SCRLLINE = PAGE-SCRLLINE + 1.
    ENDIF.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM POSITION_LIST *
    *---------------------------------------------------------------------*
    FORM POSITION_LIST.
    CALL FUNCTION 'LIST_SCROLL_LINE_TOPMOST'
    EXPORTING
    LIST_INDEX = 1
    LIST_LINE = PAGE-SCRLLINE
    EXCEPTIONS
    OTHERS = 1.
    CHECK SYST-SUBRC = 0.
    ENDFORM.
    *---------------------------------------------------------------------*
    * FORM TOP_OF_PAGE *
    *---------------------------------------------------------------------*
    FORM TOP_OF_PAGE.
    * set page-hdrlines = lines in header + 1 system generated blank line
    PAGE-HDRLINES = 5.
    ULINE.
    WRITE : /1 SYST-VLINE, 'Header'(002), AT SYST-LINSZ SYST-VLINE.
    WRITE : /1 SYST-VLINE, 'Lines'(003), AT SYST-LINSZ SYST-VLINE.
    ULINE.
    ENDFORM.

     

  • 相关阅读:
    简化窗口的控制和异常处理的复杂性
    集合运算 字典排序 按值 按键
    单条insert
    Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=
    反黑
    curl HTTP_USER_AGENT
    location.replace
    提升600百万数据的处理速度 禁止图片下载
    https://security.stackexchange.com/questions/68405/what-is-tmunblock-cgi-and-can-it-be-exploited-by-shellshock-linux-apache-w
    逻辑分离
  • 原文地址:https://www.cnblogs.com/elegantok/p/1524607.html
Copyright © 2020-2023  润新知