Sample ABAP code for SAP CRM User Status processing

The source code is as follows:

*&---------------------------------------------------------------------*
*& Report ZSTATUS_INITIAL_LOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zstatus_initial_load.

TYPES:
  BEGIN OF ty_sel_tab,
    sign   TYPE ddsign,
    option TYPE ddoption,
    low    TYPE string,
    high   TYPE string,
  END OF ty_sel_tab .
TYPES:
  tt_sel_tab TYPE STANDARD TABLE OF ty_sel_tab .

DATA: lt_tj30        TYPE STANDARD TABLE OF tj30,
      lv_valid_found TYPE abap_bool,
      lt_option      TYPE tt_sel_tab,
      lt_table       TYPE STANDARD TABLE OF zorder_guid.

SELECT stsma stonr INTO CORRESPONDING FIELDS OF TABLE lt_tj30 FROM tj30.

LOOP AT lt_tj30 ASSIGNING FIELD-SYMBOL(<tj30>).
  AT NEW stsma.
    lv_valid_found = abap_false.
  ENDAT.

  IF <tj30>-stonr IS NOT INITIAL.
    lv_valid_found = abap_true.
  ENDIF.

  AT END OF stsma.
    IF lv_valid_found = abap_true.
      DATA(ls_option) = VALUE ty_sel_tab( sign = 'I' option = 'EQ' low = <tj30>-stsma ).
      APPEND ls_option TO lt_option.
    ENDIF.
  ENDAT.

ENDLOOP.

SELECT guid INTO CORRESPONDING FIELDS OF TABLE lt_table FROM crmd_orderadm_h AS a INNER JOIN crm_jsto AS b
   ON a~guid = b~objnr WHERE b~stsma IN lt_option.

DELETE FROM zorder_guid.
INSERT zorder_guid FROM TABLE lt_table.
COMMIT WORK AND WAIT.
WRITE: / 'table inserted'.
BREAK-POINT.

The main function of this ABAP program is to retrieve data from two SAP CRM data tables and insert data that meets specific conditions into a custom data table. The program also includes some control logic for selecting data that meets the conditions and performing submission operations.

Let me explain in detail what this program does and provide an example:

  1. The program starts :

    • REPORT zstatus_initial_load.: This line specifies the name of the program.
  2. Type definition :

    • After the program starts, two data structures (TYPES) ​​are defined. The first one is ty_sel_tabused to store information about query selection conditions, including signature (sign), option (option), lower limit (low) and upper limit (high). The second one is tt_sel_tab, is ty_sel_taba standard table type of type.
  3. Data statement :

    • DATAStatements are used to declare various data tables and variables, including lt_tj30, lv_valid_found, lt_optionand lt_table.
  4. Data query :

    • SELECTstatement tj30selects data from a table and stores the results in lt_tj30the table.
  5. Loop processing :

    • Use LOOPthe statement to iterate through lt_tj30the data in the table. In each iteration, use AT NEW stsmaand AT END OF stsmacontrol logic to perform certain operations.
  6. Condition check :

    • In the loop, the program checks to see <tj30>-stonrif is empty. If not empty, sets lv_valid_foundto true ( abap_true).
  7. Data filtering :

    • Within AT END OF stsmathe control logic, if lv_valid_foundis true, the program creates a selection condition that matches the specified criteria ls_optionand then appends it to lt_optionthe table.
  8. Second data query :

    • After the loop ends, the program executes the second SELECTstatement, selects data from crmd_orderadm_htable and crm_jstotable, and stores the result in lt_tabletable. This query uses the selection criteria built earlier lt_option.
  9. Data operations :

    • DELETE FROM zorder_guid.: Clear zorder_guidthe custom data table named.

    • INSERT zorder_guid FROM TABLE lt_table.: lt_tableInsert data from the table into zorder_guidthe table.

    • COMMIT WORK AND WAIT.: Commit the database transaction.

  10. Outputs and interrupts :

    • WRITE: / 'table inserted'.: Output a text message on the screen indicating that the data has been inserted.

    • BREAK-POINT.: Insert breakpoints for debugging during program execution.

Now, let's use an example to illustrate what the program does:

Suppose you manage customer order data in a SAP CRM system. tj30The table contains order status information, crmd_orderadm_hand the and crm_jstotables contain order details. You want to tj30select order statuses from a table that match certain criteria and insert the details of those orders into a custom table zorder_guid.

For example, you want to select all orders with an order status of 'Approved'. After the program executes, it iterates through tj30the table, finds all orders with status 'Approved', and inserts their details into zorder_guidthe table. Finally, the message 'table inserted' will appear on the screen, indicating that the operation is complete.

This is a simple example of how a program can select data from one table and insert it into another table based on selection criteria. In actual applications, the selection conditions and data tables in the program can be modified according to specific business needs to achieve different data processing operations.

Guess you like

Origin blog.csdn.net/i042416/article/details/132861482