ABAP Select data from SAP table /ACCGO/CAS_S_PRICING_CANCEL into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP /ACCGO/CAS_S_PRICING_CANCEL table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /ACCGO/CAS_S_PRICING_CANCEL. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the /ACCGO/CAS_S_PRICING_CANCEL table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_/ACCGO/CAS_S_PRICING_CANCEL TYPE STANDARD TABLE OF /ACCGO/CAS_S_PRICING_CANCEL, WA_/ACCGO/CAS_S_PRICING_CANCEL TYPE /ACCGO/CAS_S_PRICING_CANCEL, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: </ACCGO/CAS_S_PRICING_CANCEL> TYPE /ACCGO/CAS_S_PRICING_CANCEL. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/ACCGO/CAS_S_PRICING_CANCEL. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /ACCGO/CAS_S_PRICING_CANCEL INTO TABLE IT_/ACCGO/CAS_S_PRICING_CANCEL. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /ACCGO/CAS_S_PRICING_CANCEL * INTO TABLE @DATA(IT_/ACCGO/CAS_S_PRICING_CANCEL2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_/ACCGO/CAS_S_PRICING_CANCEL INDEX 1 INTO DATA(WA_/ACCGO/CAS_S_PRICING_CANCEL2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/ACCGO/CAS_S_PRICING_CANCEL ASSIGNING </ACCGO/CAS_S_PRICING_CANCEL>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</ACCGO/CAS_S_PRICING_CANCEL>-ACTION = 1.
</ACCGO/CAS_S_PRICING_CANCEL>-TRADINGCONTRACTNUMBER = 1.
</ACCGO/CAS_S_PRICING_CANCEL>-TRADINGCONTRACTITEM = 1.
</ACCGO/CAS_S_PRICING_CANCEL>-PRICINGLOTID = 1.
</ACCGO/CAS_S_PRICING_CANCEL>-CLOSEWITHEQUITY = 1.
ENDLOOP. LOOP AT IT_/ACCGO/CAS_S_PRICING_CANCEL INTO WA_/ACCGO/CAS_S_PRICING_CANCEL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/ACCGO/CAS_S_PRICING_CANCEL-CLOSEWITHOUTEQUITY, sy-vline,
WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELLATIONTYPE, sy-vline,
WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELLATIONTYPETEXT, sy-vline,
WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELLATIONCODE, sy-vline,
WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELLATIONCODETEXT, sy-vline,
WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELLATIONDATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/ACCGO/CAS_S_PRICING_CANCEL you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/ACCGO/CAS_S_PRICING_CANCEL TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/ACCGO/CAS_S_PRICING_CANCEL INTO WA_/ACCGO/CAS_S_PRICING_CANCEL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ALPHA, internal->external for field TRADINGCONTRACTNUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-TRADINGCONTRACTNUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-TRADINGCONTRACTNUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BASISUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-BASISUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-BASISUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field FETCHEDBASISUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-FETCHEDBASISUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-FETCHEDBASISUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field FUTURESUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-FUTURESUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-FUTURESUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field FETCHEDFUTURESUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-FETCHEDFUTURESUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-FETCHEDFUTURESUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-UOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CANCELNONHEDGEUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELNONHEDGEUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELNONHEDGEUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CANCELFETCHNONHEDGEUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELFETCHNONHEDGEUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCELFETCHNONHEDGEUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CANCQTYUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCQTYUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_PRICING_CANCEL-CANCQTYUOM.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/ACCGO/CAS_S_PRICING_CANCEL_STR,
ACTION TYPE STRING,
TRADINGCONTRACTNUMBER TYPE STRING,
TRADINGCONTRACTITEM TYPE STRING,
PRICINGLOTID TYPE STRING,
CLOSEWITHEQUITY TYPE STRING,
CLOSEWITHOUTEQUITY TYPE STRING,
CANCELLATIONTYPE TYPE STRING,
CANCELLATIONTYPETEXT TYPE STRING,
CANCELLATIONCODE TYPE STRING,
CANCELLATIONCODETEXT TYPE STRING,
CANCELLATIONDATE TYPE STRING,
EXCHANGERATETYPE TYPE STRING,
TARGETCURRENCY TYPE STRING,
BASISAMOUNT TYPE STRING,
BASISCURRENCY TYPE STRING,
BASISPERUNIT TYPE STRING,
BASISUOM TYPE STRING,
FETCHEDBASISAMOUNT TYPE STRING,
FETCHEDBASISCURRENCY TYPE STRING,
FETCHEDBASISPERUNIT TYPE STRING,
FETCHEDBASISUOM TYPE STRING,
BASISOVERRIDEREASON TYPE STRING,
FUTURESAMOUNT TYPE STRING,
FUTURESCURRENCY TYPE STRING,
FUTURESPERUNIT TYPE STRING,
FUTURESUOM TYPE STRING,
FETCHEDFUTURESAMOUNT TYPE STRING,
FETCHEDFUTURESCURRENCY TYPE STRING,
FETCHEDFUTURESPERUNIT TYPE STRING,
FETCHEDFUTURESUOM TYPE STRING,
FUTURESOVERRIDEREASON TYPE STRING,
FEE TYPE STRING,
CURRENCY TYPE STRING,
PRICINGUNIT TYPE STRING,
UOM TYPE STRING,
EFFECTIVEDATE TYPE STRING,
GROUPINGCRITERIA TYPE STRING,
CANCELNONHEDGEAMOUNT TYPE STRING,
CANCELNONHEDGECURRENCY TYPE STRING,
CANCELNONHEDGEPERUNIT TYPE STRING,
CANCELNONHEDGEUOM TYPE STRING,
CANCELFETCHNONHEDGEAMOUNT TYPE STRING,
CANCELFETCHNONHEDGECURRENCY TYPE STRING,
CANCELFETCHNONHEDGEPERUNIT TYPE STRING,
CANCELFETCHNONHEDGEUOM TYPE STRING,
NONHEDGEOVERRIDEREASON TYPE STRING,
PRICINGAPPROACH TYPE STRING,
EQUITY TYPE STRING,
CANCQTY TYPE STRING,
CANCQTYUOM TYPE STRING,
CANCELLATIONGUID TYPE STRING,
NEWPLOTID TYPE STRING,
PRICINGLOTSTATUS TYPE STRING,
UX_FC_UOM TYPE STRING,
UXCANCELLATIONTYPE TYPE STRING,
UXCANCELLATIONTYPETEXT TYPE STRING,
UXCANCELLATIONCODE TYPE STRING,
UXCANCELLATIONCODETEXT TYPE STRING,
UXTARGETCURRENCY TYPE STRING,END OF T_EKKO_STR. DATA: WA_/ACCGO/CAS_S_PRICING_CANCEL_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-ACTION sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-TRADINGCONTRACTNUMBER sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-TRADINGCONTRACTITEM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-PRICINGLOTID sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CLOSEWITHEQUITY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CLOSEWITHOUTEQUITY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONTYPE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONTYPETEXT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONCODE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONCODETEXT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONDATE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-EXCHANGERATETYPE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-TARGETCURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-BASISAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-BASISCURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-BASISPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-BASISUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDBASISAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDBASISCURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDBASISPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDBASISUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-BASISOVERRIDEREASON sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FUTURESAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FUTURESCURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FUTURESPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FUTURESUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDFUTURESAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDFUTURESCURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDFUTURESPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FETCHEDFUTURESUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FUTURESOVERRIDEREASON sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-FEE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-PRICINGUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-EFFECTIVEDATE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-GROUPINGCRITERIA sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELNONHEDGEAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELNONHEDGECURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELNONHEDGEPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELNONHEDGEUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELFETCHNONHEDGEAMOUNT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELFETCHNONHEDGECURRENCY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELFETCHNONHEDGEPERUNIT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELFETCHNONHEDGEUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-NONHEDGEOVERRIDEREASON sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-PRICINGAPPROACH sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-EQUITY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCQTY sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCQTYUOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-CANCELLATIONGUID sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-NEWPLOTID sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-PRICINGLOTSTATUS sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UX_FC_UOM sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UXCANCELLATIONTYPE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UXCANCELLATIONTYPETEXT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UXCANCELLATIONCODE sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UXCANCELLATIONCODETEXT sy-vline
WA_/ACCGO/CAS_S_PRICING_CANCEL_STR-UXTARGETCURRENCY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.