目录
1.Background and requirements.
3.Maintain the system Bar codes in SE73.
4.Set form style and draw your form.
5. The mainly control in program code.
1.Background and requirements.
Sometimes we need to print QR code via smartforms in SAP, but the probelm inculdes is the unfix size and position of the QR code. Because the different QR code contnent
Now, flow those steps can achive it.
2.Solution.
Because the scanner ignores the space in front of the code.( middle space are not ingored, and multiple blanks are considered to be one ).
So,we can caculate the largest length we may used, and then fill the blank in front of the code contnent if they are not enough long.
3.Maintain the system Bar codes in SE73.
Please remeber this Bar code Name, which will be used in SF.
4.Set form style and draw your form.
Then used this character formats with the field of QR code in you form.
5. The mainly control in program code.
*&---------------------------------------------------------------------*
*& Report ZHANS_TEST001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zhans_test01.
TYPES: BEGIN OF ty_out,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
ktmng TYPE ktmng,
matnr TYPE matnr,
maktx TYPE maktx,
END OF ty_out.
DATA: gs_out TYPE ty_out.
DATA: gt_out TYPE TABLE OF ty_out.
DATA: gv_length_total TYPE i.
DATA: gv_ktmng TYPE string.
DATA: gv_fname TYPE rs38l_fnam.
DATA: gs_ssfctrlop TYPE ssfctrlop .
DATA: gv_number TYPE I.
*gs_ssfctrlop-no_dialog = 'X'.
*gs_ssfctrlop-preview = 'X'.
gs_ssfctrlop-no_open = 'X'.
gs_ssfctrlop-no_close = 'X'.
"In order to more convenient,
"we assume the largest QR_code length is 200.
DATA: gv_qr_code TYPE char200.
" get test data
" we assume that the QR_code consist of PO number,PO item
" PO quantity, matrial and material description.
SELECT ekpo~ebeln
ekpo~ebelp
ekpo~ktmng
ekpo~matnr
makt~maktx
FROM ekpo
INNER JOIN makt ON ekpo~matnr = makt~matnr AND makt~spras = '1'
INTO CORRESPONDING FIELDS OF TABLE gt_out
WHERE ekpo~aedat > '20230501'.
PERFORM get_funtion_name.
PERFORM ssf_open.
CLEAR gv_number.
LOOP AT gt_out INTO gs_out FROM 1 TO 5 .
CLEAR: gv_qr_code,
gv_ktmng,
gv_length_total.
"1. remove the leading zero and caculate the actual length of each component.
"2. caculate all component total length.
PERFORM caculate_each_length USING 'EBELN' gv_length_total.
PERFORM caculate_each_length USING 'EBELP' gv_length_total.
"Attention:
" KTMNG is a quantity field, can't be remove the leading zero.
* PERFORM caculate_each_length USING 'KTMNG' gv_length_total.
PERFORM caculate_each_length USING 'MATNR' gv_length_total.
PERFORM caculate_each_length USING 'MAKTX' gv_length_total.
"3.fill in front of the QR_code with blank for the rest length.
" via this way, we can keep the QR_code always having the same length and size
" but please be careful, we need remove the leading zero first if each componet have.
"concatenate only be used to C N D T and String.
gv_ktmng = gs_out-ktmng .
gv_length_total = gv_length_total + strlen( gv_ktmng ).
CONCATENATE gs_out-ebeln
gs_out-ebelp
gv_ktmng
gs_out-matnr
gs_out-maktx
INTO gv_qr_code SEPARATED BY ','.
DO ( 200 - gv_length_total - 5 ) TIMES .
CONCATENATE ''
gv_qr_code
INTO gv_qr_code SEPARATED BY ''.
ENDDO.
gv_number = gv_number + 1.
PERFORM print_qr_code.
ENDLOOP.
PERFORM ssf_close.
*&---------------------------------------------------------------------*
*& Form CACULATE_EACH_LENGTH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0102 text
* -->P_gv_length_total text
*----------------------------------------------------------------------*
FORM caculate_each_length USING value(p_field)
p_gv_length_total.
FIELD-SYMBOLS <lv_any> .
ASSIGN COMPONENT p_field OF STRUCTURE gs_out TO <lv_any>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = <lv_any>
IMPORTING
output = <lv_any>.
p_gv_length_total = p_gv_length_total + strlen( <lv_any> ).
ENDFORM. " CACULATE_EACH_LENGTH
*&---------------------------------------------------------------------*
*& Form PRINT_QR_CODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_qr_code .
CALL FUNCTION gv_fname
EXPORTING
control_parameters = gs_ssfctrlop
iv_qr_code = gv_qr_code
iv_number = gv_number.
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. " PRINT_QR_CODE
*&---------------------------------------------------------------------*
*& Form GET_FUNTION_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_funtion_name .
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZHANS_TEST_FIX_QR_CODE_02'
IMPORTING
fm_name = gv_fname.
ENDFORM. " GET_FUNTION_NAME
*&---------------------------------------------------------------------*
*& Form SSF_OPEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ssf_open .
CALL FUNCTION 'SSF_OPEN'
EXPORTING
control_parameters = gs_ssfctrlop
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
ENDFORM. " SSF_OPEN
*&---------------------------------------------------------------------*
*& Form SSF_CLOSE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ssf_close .
CALL FUNCTION 'SSF_CLOSE'
* IMPORTING
* JOB_OUTPUT_INFO =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
OTHERS = 4.
ENDFORM. " SSF_CLOSE
6.Test result.
Now, you can see that they are the same size even if the QR code contnent is different.